0

I have a Visual Studio 2012 solution containing several projects, some in C and some in Fortran (using Intel Composer XE 2013). I frequently call from the Fortran code into the C code using the iso_c_binding utility, but I've noticed that I cannot debug the C code effectively. While debugging the Fortran code, I can view the contents of variables just fine, but if I step into the C code, suddenly they lose their sanity. Most variables just claim to be undefined; anything passed to the function will contain incorrect values (but it still does differentiate between pointers and objects/POD).

I can still step through the code; it seems to mostly follow the expected sequence of execution, but sometimes it does jump around a bit, which I'm familiar with from debugging compiler-optimized code on Linux with gdb.

I have a separate solution that also has C and Fortran projects. Both call into the same C project from the first solution, and in both cases, I can again debug successfully until I step into the C project from the first solution, at which point I have the same problems.

What am I doing wrong?

4
  • It sounds like you hit the nail on the head. VC is pretty aggressive when it comes to optimizing local variables and parameters into registers, etc. I can only suggest you debug via the disassembly window, which, if you have debug-symbols, will at least show you what is happening at each line. Commented Oct 9, 2013 at 22:37
  • Are all optimizations off? Commented Oct 9, 2013 at 22:56
  • @kotlomoy, I'm experiencing this problem no matter what the optimization property is set to. If there are other things to check, let me know. Commented Oct 10, 2013 at 13:42
  • @WhozCraig, thanks for the tip. The disassembler does work, but certainly it is not unreasonable for me to want the be able to use the full debugging experience. I can get it for my top-level C projects, but not when they call into this other project, so I know it should be possible. Commented Oct 10, 2013 at 13:45

1 Answer 1

2

This is the standard bat signal for debugging code that was optimized. You'll need to rearrange you build settings so your Fortran code links to the non-optimized Debug build of the C code.

There are no breadcrumbs in your question as to how that went wrong in the first place. Start by checking which library is getting linked into your Fortran program and make sure that you can see distinct libraries generated for your C project in the Debug and Release builds. You need to link the one created by the Debug build.

Sign up to request clarification or add additional context in comments.

1 Comment

Very confusing. I had tried deactivating the optimizations before, but I think there was another problem with compilation or link order, and so I had to fix that first. Thanks for pointing me in the right direction!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.