Search code examples
c++debuggingsconsvisual-studio-2010

How to generate MSVC solution with debugging information using scons?


I'm writing scons script for a c++ project that is intended to be cross-platform. In windows, the script generates msvc solution. The script snippet is as follows:

ENV={'PATH':os.environ['PATH']}
if build_type=='Release':
    CCFLAGS=['/Ox','/EHsc','/DNDEBUG','/W3']
else:
    CCFLAGS=['/Zi','/EHsc','/W3']
ENV['TMP']=os.environ['TMP']
if os_architecture=='32bit':
    arc='x86'
else:
    arc='amd64'
env=Environment(CCFLAGS=CCFLAGS,CPPPATH=include_path,LIBPATH=lib_path,RPATH=lib_path,LIBS=libs,ENV=ENV,MSVS_ARCH=arc,TARGET_ARCH=arc)

In debug mode the solution file is supposed to contain debugging information. However when I debug code in debug mode, I get "cannot find debugging information or debugging information mismatch" warning. Cannot figure out why. There is one ".pdb" file generated.


Solution

  • The Zi parameter will tell VS to create a pdb's during the compile time phase, however, you still need to specify the link-time pdb generation (yeah, its quite redundant, but there is probably some reason for the ultra fine-grained control). If the PDB your seeing is named vc###.pdb (where ### is your vc compiler version) then that is the compile-time pdb for your obj files, -not- your debuggable link-time pdb for your actual dll.

    Anywho, I added the following line to scons and now I have a debuggable proper .pdb:

    # Produce one .PDB file per .OBJ when compiling, then merge them when linking.
    # Doing this enables parallel builds to work properly (the -j parameter).
    # See: http://www.scons.org/doc/HTML/scons-man.html section CCPDBFLAGS
    # 
    env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
    

    Which I got from the following very very helpful sample SConscript http://www.scons.org/wiki/MsvcIncrementalLinking