Ask Your Question

How do I convince Visual Studio to go through OpenCV source files while debugging?

asked 2016-01-21 08:52:16 -0600

nyd gravatar image

Steps I've taken:

  1. Built OpenCV from source, so that I have the *d.pdb and *d.dll in the same folder (C:\OpenCV\bin)
  2. Added C:\OpenCV\bin to Tools -> Options -> Debugging -> Symbols. Note: I never got to see that it loads any pdb from this folder, but it doas load the pdbs from Microsoft's server.
  3. Added C:\OpenCV\bin to the system PATH variable, so that the executable has the libraries available at run time
  4. Added C:\OpenCV\modules to Solution's Property Pages -> Common Properties -> Debug Source Files (it looks like this would do the trick, but it doesn't)
  5. Added C:\OpenCV\install\include to Project's Property Page -> Configuration Properties -> C/C++ -> General -> Additional include directories, so that I can include OpenCV's header files, for this I had to also build the install project, which was not selected by default.
  6. Added C:\OpenCV\lib\Debug to Project's Property Page -> Configuration Properties -> Linker -> General -> Additional library directories, so that it knows where to look for .lib files
  7. Added all *d.lib files from C:\OpenCV\lib\Debug (where there are also some .pdb, by the way) to Project's Property Page -> Configuration Properties -> Linker -> Additional Dependencies, because otherwise apparently it doesn't know that I'd like to use everything in the folder I just specified previously.

Everything was done under Debug configuration.

The result is that I can build, I can debug, but if I step into some function, it gets me to the header file, instead of the source file, which is not very useful.

Does anyone know what did I miss to set up so I could go through OpenCV source files when I'm debugging my own project?

I run Visual Studio 2015 Community edition on Windows 10 if it has any importance...

edit retag flag offensive close merge delete


It was possible before but for me it stopped working at OpenCV3.0. I am guessing it has something to do with the hidden implementation structure of the OpenCV classes.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-21 09:30:23 -0600 )edit

that's quite bad. If there really is no solution debugging becomes impossible unless you have an actual error. How do you manage to do any work without this? Also it would be a lot easier to learn how OpenCV works and implicitly the concepts behind it, by going through the code.

nyd gravatar imagenyd ( 2016-01-21 09:47:55 -0600 )edit

I haven't got problems using VS2015 and opencv 3.1. I'm not working like you. I use CMake to build opencv and my own program. I don't install opencv and copy only dll in exe folder. I work with static lib too and i don't need to copy dll (except ffmpeg opencv dll) and I can debug in opencv source code. With vs 2015 2013 and 2012 professionnal edition I can debug opencv source code if source code is sync with dll.

LBerger gravatar imageLBerger ( 2016-01-21 10:24:59 -0600 )edit

Did you build with BUILDALL or the INSTALL? You have to build with INSTALL and set the environment variable to the install folder or copy the whole folder anywhere you like and set the variable to that path. Now you have to link your project against the lib folder and the include folder and copy the opencv dll('s) to your .exe folder. There is no need to link against the module folder. It should work fine this way.

matman gravatar imagematman ( 2016-01-21 13:21:06 -0600 )edit

that's what I did the first time, and unfortunately it did not work, that's why I proceeded with other things like what I described in my question. The thing is that after I did everything I described above and a few more other things (disabled optimization, etc) it started working somehow, but unfortunately I don't know exactly what did the trick. If I am to give some advice to anyone that has the same problem, is "keep trying" cause it's definitely working with the right incantation. When you start stepping into the code (F11), keep pressing it until you go over the headers, don't just assume that it's not working just because you've been through 10 headers already and there's no source code yet. Not really a good answer, but it might help someone...

nyd gravatar imagenyd ( 2016-01-22 02:30:21 -0600 )edit

@Eduardo, yes, did that, step 4 in my question.

nyd gravatar imagenyd ( 2016-01-22 02:32:10 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-01-25 11:59:45 -0600

pklab gravatar image

updated 2016-01-25 12:06:25 -0600

A bit OT but I hope this helps !

All the job is done by .pdb files because it maps the source code to instructions.

Ensure that pdb files match exactly (are generated from) your DLL. The debugger will not load a .pdb file that does not match exactly the executable being debugged. 2 executables could have same source code but different pdb.

In the IDE output window , check if .pdb files for opencv DLLs are loaded at start up. For each DLL used in the application you should see opencv_XXX.dll. Symbols loaded. If you see opencv_XXX.dll. Cannot find or open the PDB file your pdb files should stay

  • in the executable path or with application dll
  • where they have been created at opencv build time
  • in a path specified by IDE Tool>Options>Debugging>Symbol add a new symbol file locations

When the IDE can find the pdb files (the output shows opencv_XXX.dll. Symbols loaded) the debugger should work fine.

In case you can't locate the source code for OpenCV you have to check the path stored in the pdb files. To do this you need to dump info stored in pdb. You can do this using pdbInspector or The Dia2dump sample is installed with Visual Studio. Once you have built Dia2dump, run it Dia2dump -sf opencv_XXX.pdb > file.txt and inspect file.txt if sources path listed for opencv function are valid path. For example on my computer Dia2dump -sf opencv_annotationd.pdb produces:

z:\libs\opencv\3.0.0\sources\opencv\apps\annotation\opencv_annotation.cpp (MD5: 668BA49F0E20B8C4C84F00A99DDAFFFA)

More info from MSDN Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger

edit flag offensive delete link more

answered 2016-01-25 12:10:18 -0600

mynameisjohnj gravatar image

updated 2016-01-25 12:14:08 -0600

I would say that pklab's answer is the right one. However, I am very lazy and dumb, but I needed to do this with the cudafilters library the other day and did it as follows. The only caveat to this is that you need the Visual studio solution created by CMake on hand.

  1. Open up your solution of the project you're working on, and make sure you're on Debug
  2. Right click your solution in the solution explorer, select Add Existing Project, and add the .vcxproj that corresponds to the OpenCV module you'd like to debug. The project should now be in your solution.
  3. If you link against the debug libraries made by OpenCV, then stepping into these functions should allow you to see the OpenCV code.

The trick is having the OpenCV module project alongside the project you're working on in the Solution explorer. Once you're done you can remove the reference to the OpenCV project and continue.

edit flag offensive delete link more

Question Tools



Asked: 2016-01-21 08:52:16 -0600

Seen: 5,262 times

Last updated: Jan 25 '16