Search code examples
c++visual-studiodebuggingdebug-symbolspdb-files

How to integrate msvc CL /DEBUG with visual studio devenv /DebugExe


I use msvc (visual studio cl.exe) on the command line to compile one of my c++ projects.

To do so, I use the Visual Studio Community 2019 developer console In cmd, I initialize my environment by calling:

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" 

Then I compile my code with:

cl /DEBUG main.cpp SDL2-2.0.14\lib\x86\SDL2.lib portaudio_x86.lib /IPortAudio\include /ISDL2-2.0.14\include

Generally, I can run my program by just calling

main.exe

But if I want to debug it in visual studio, I use

devenv /DebugExe main.exe

In visual studio, after I hit "▶️start" in the top toolbar, the program will run fine, but when I hit an exception, the symbols wont load. For example: Visual Studio Community 2019 Debugger

How can I get Visual Studio to load the symbol file correctly and show me the LINE NUMBER of the error?

Thanks,

Mike


Solution

  • To summarize the answers provided in the comments to the question:

    The compiling and linking must be done in one step since the executable is being compiled outside of a visual studio project:

    to compile and link:

    cl /Zi /EHsc <compiler options> <source files> /link <linker options> <library and resource files>
    

    to debug:

    devenv /DebugExe <executable>