Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug an external library (OpenCV) in Visual C++?

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.

like image 545
neuviemeporte Avatar asked Apr 27 '10 12:04

neuviemeporte


2 Answers

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 Debug 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.

like image 58
neuviemeporte Avatar answered Oct 15 '22 09:10

neuviemeporte


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.

like image 26
kmontgom Avatar answered Oct 15 '22 07:10

kmontgom