views:

1129

answers:

3

I am developing a project in VC++2008. The project uses the OpenCV library (but I guess this applies to any other library). I am working with the Debug configuration, the linker properties include the debug versions of the library .lib's as additional dependencies. In VC++ Directories under Tools|Options i set up the include directory, the .lib directory, the source directories for the library as well. I get an error while calling one of the functions from the library and I'd like to see exactly what that function is doing. The line that produces the error is:

double error = cvStereoCalibrate(&calObjPointsM, &img1PointsM, &img2PointsM,
 &pointCountsM, 
 &cam1M, &dist1M, &cam2M, &dist2M, imgSize, &rotM, &transM, NULL, NULL,
 cvTermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 100, 1e-5));

I set up a breakpoint at this line to see how the cvStereoCalibrate() function fails. Unfortunately the debugger won't show the source code for this function when I hit "Step into". It skips immediately to the cvTermCriteria() (which is a simple inline, macro-kinda function) and show its contents. Is there anything else I need to do to be able to enter the external library functions in the debugger?

EDIT: I think the cvTermCriteria() function shows in the debugger, because it's defined in a header file, therefore immediately accesible to the project.

EDIT2: The .pdb files were missing for the library files, now I recompiled the OpenCV library in Visual C++ in Debug configuration, the .pdb files exist but are still somehow invisible to the debugger:

Loaded 'C:\Users\DarekSz\Documents\Visual Studio 2008\Projects\libcci\Debug\ccisample.exe', Symbols loaded.
'ccisample.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll'
'ccisample.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'ccisample.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'ccisample.exe': Loaded 'C:\OpenCV2.1\bin\cv210d.dll'
'ccisample.exe': Loaded 'C:\OpenCV2.1\bin\cxcore210d.dll'

The symbols aren't loaded apparently for the opencv dlls. Still, the .pdb files exist in the \bin directory.

+1  A: 

Confirm: are you actually compiling the OpenCV library from source, or are you just linking against it?

A couple of possibilities come to mind:

It sounds like the debug info for the OpenCV library is not available (the PDB files). You may have to extend PATH to reference the directory containing these files. It seems to me that there is a way of doing this from VC++ but I'm a few years out from using the tool...

Is cvStererCalibrate also a "macro function"? If so, find out what real function it refers to and set the breakpoint in the library.

Finally, although you have already said so, it never hurts to go back and confirm that full debugging has been activated for everything in the project, including external libraries.

I don't know if this helps, but its a good place to start.

kmontgom
I am just linking against static opencv libs. I can't see the .pdb files anywhere in the library tree. I thought the special -d suffix lib files already include all the necessary information.The function is not a macro, just a regular C-style function.What kind of option enables debugging for external libraries?
neuviemeporte
Unless the extern libraries are compiled with VC++ debug info, you will have to actually recreate the library using VC++, and set all required flags for using debug info.Try creating a new VC++ static lib project based on the OpenCV source, compile it with full debug info and then have your project link against the new OpenCV library.
kmontgom
Okay, I'll try that. Regarding the difference between the accesiblity of the cvTerm... and cvStereo... functions, I guess it's because cvTerm is defined in a header file, not in the lib object.
neuviemeporte
Question is: is cvStereo... also #define'd as something? Regardless, the #define'd "functions" have to be backed by real code.
kmontgom
On a side note, you should also look at the "Related" items along the right side of the webpage. Seems like a couple of them may relate to your problem.... (e.g. http://stackoverflow.com/questions/1672273/how-to-configure-opencv-1-2-in-visual-c)
kmontgom
No, it's just as plain and boring a C-style function as can be conceived of. ;)
neuviemeporte
I compiled the library with VC++, obtained debug versions of the lib along with .pdb files, set up the project to use the paths to the new lib version, still can't debug inside the library functions. :/
neuviemeporte
Ahhh... the joys of C++ development. I need to chew on this a while.I don't suppose that there's any useful output in the debug console, something like "debug symbols for .... could not be loaded"?
kmontgom
There's no message saying they could not be loaded, but there's no message saying they were loaded either, as is the case with some other libs I'm linking against. The question's edit reflects this.
neuviemeporte
There are a bunch of "grasping at straws" things that could be suggested at this point; things like doing a complete clean of intermediate files, deleting precompiled headers, even shutting down and restarting Visual Studio. You've probably done that already.In my experience, its usually a library mismatch, i.e. a release mode library has been selected, but mistaken for a debug-mode library.Is there someone else you can go to for an independent review of your setup? Sometimes a second pair of eyes can see things we routinely skip over. God knows its happened many times to me in the past.
kmontgom
Yes, I did try all these measures. I finally managed to get the debugger to load the symbols (after ogling at the output for a few hours, I noticed the dlls were loaded by the export libs from a different directory which lacked the .pdb information). However, the debugger still won't step into the external functions.
neuviemeporte
Can you post a small sample application somewhere?
kmontgom
In what format? I can zip the app and the dlls and pdbs together, but if you have the OpenCV library, a simple win32 console application which just calls cvStereoCalibrate(8xNULL, cvSize(0,0), 4xNULL); from main() serves as a showcase - the debugger won't step into the function even though the symbols are loaded for OpenCV dlls (which can be verified in the Modules dock window).
neuviemeporte
Actually, it works for an isolated case. :-O Now I have to figure out why. My bad.
neuviemeporte
No such thing as bad where C++ is concerned.We have a TV commercial over here with a jingle which seems appropriate -- for a cough and cold medicine: "tastes bad, but it works". Same thing with C++.Keep us in the loop with your progress.
kmontgom
Naturally, thanks for your time.
neuviemeporte
+1  A: 

To sum up all the activity in the comments: the key to the solution was to rebuild the library in VC++ to obtain the .pdb (program database) files for debugging, the precompiled "-d" suffix libraries weren't enough. Still, the import libs for the library dlls made the program load precompiled dlls from the OpenCV package tree, not the ones from my build with the .pdb information (the paths were similar so I didn't notice at first). The path to the .pdb files was provided in Tools|Options, but these files weren't loaded because of module version mismatch (obviously). Once I copied the correct dlls and their respective .pdb files to the application directory, the debugger started working inside the library functions.

neuviemeporte