How do I generate PDB/DWARF symbols and use them with GCC for C++?

To generate PDB or DWARF symbols using GCC for C++, you need to follow specific compilation flags based on your platform and the desired debugging format. PDB (Program Database) is primarily used on Windows, while DWARF (Debugging With Attributed Record Formats) is commonly used on Unix-like systems.

Generating PDB Symbols on Windows

To create PDB symbols with GCC on Windows, you can use the MinGW-w64 toolchain. Use the following flags:

g++ -g -Wl,--pdb=output.pdb your_source_file.cpp -o your_executable.exe

Generating DWARF Symbols on Unix-like Systems

For DWARF symbols, you just need to use the `-g` flag when compiling your C++ code. No additional linking step for DWARF is required.

g++ -g your_source_file.cpp -o your_executable

Using Generated Symbols

After compiling your program with the appropriate debugging information, you can either use a debugger like GDB (for DWARF) or Visual Studio (for PDB). Ensure that you have the right environment setup for your chosen platform and toolchain.


C++ GCC PDB DWARF symbols debugging MinGW-w64 GDB Visual Studio