How to generate .pdb file in Visual Studio 2019 for C++ from command line
Asked Answered
G

2

5

I am using cl.exe C++ compiler in Visual Studio 2019 from the command line. But, I am unable to set the required flag to produce a .pdb file to debug in a separate debugger. I tried /DEBUG:FULL /FI /Fd, etc., as read in several posts, but no .pdb file is generated.

I also tried to configure the IDE as per different instructions, but still, no .pdb file is created.

What is the command-line flag to be used to produce a .pdb file?

cl.exe myprogram.cpp /DEBUG:FULL /Fdmyprogram.pdb /Famyprogram.asm /Femyprogram.exe

Geldens answered 10/9, 2021 at 19:57 Comment(1)
See learn.microsoft.com/en-us/cpp/build/reference/… Note this is a link not a cl option, Question why use cl from the command line? Why not the IDE or if you need to use the command line then MSBuild or CMake ?Forefront
M
3

The PDB file is generated by linker, not compiler directly.

Basically, just generate an executable or dll file, by linking the *.obj files.

While GCC can directly link, the MSVC has a completely different *.exe file for that purpose.

See the docs for linker (link.exe):
https://learn.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-160

Or compiler (cl.exe):
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-command-line-syntax?view=msvc-160

Manslaughter answered 10/9, 2021 at 20:3 Comment(0)
V
3

You can add linker options after /link command. Try

cl.exe myprogram.cpp /Z7
Violaviolable answered 7/1, 2023 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.