问题
I am using scons to compile with vc10 and renesas compiler.
Is there any commands to get an executable in debug mode?
If I executed my project with the command "scons
and enter" it is going to release mode.
I am unable to debug that .exe file using the visual studio debugger.
Can anyone tell me how to get the debugging executable in debug mode? Is there any commands or flags to set in scons?
回答1:
To get the executable in debug mode, its just a simple matter of adding the appropriate compiler debug flags to the CXXFLAGS construction variable, as follows:
env = Environment()
env.Append(CXXFLAGS = ['/DEBUG'])
But this is rather basic, and I imagine you would want to be able to control when the executable is compiled in debug mode via the command line. This can be done with command line targets or command line options (like debug=1)
To use targets, you could do something like this:
envRelease = Environment()
envDebug = Environment()
envDebug.Append(CXXFLAGS = ['/DEBUG'])
targetRelease = envRelease.Program(target = 'helloWorld', source = 'helloWorld.cc')
# This makes the release target the default
envRelease.Default(targetRelease)
targetDebug = envDebug.Program(target = 'helloWorldDebug', source = 'helloWorld.cc')
envDebug.Alias('debug', targetDebug)
If you execute SCons with no command line targets, then the release version will be built, as specified by the envRelease.Default()
function. If you execute SCons with a debug target, like this: scons debug
then the debug version will be built as specified by the envDebug.Alias()
function.
Another way to do this is with command-line arguments, like this: scons debug=0
or scons debug=1
, which would allow you to perform some logic in your build scripts, thus allowing you to more easily control the variant-dir, etc, as follows:
env = Environment()
# You can use the ARGUMENTS SCons map
debug = ARGUMENTS.get('debug', 0)
if int(debug):
env.Append(CXXFLAGS = ['/DEBUG'])
env.VariantDir(...)
else:
env.VariantDir(...)
env.Program(target = 'helloWorld', source = 'helloWorld.cc')
Look here for more command line handling options.
And one final option, that I prefer is to just always build both versions, each in their respective variantDir (build/vc10/release and build/vc10/debug for instance).
envRelease = Environment()
envDebug = Environment()
envDebug.Append(CXXFLAGS = ['/DEBUG'])
envRelease.VariantDir(...)
targetRelease = envRelease.Program(target = 'helloWorld', source = 'helloWorld.cc')
# This makes the release target the default
envRelease.Default(targetRelease)
# This allows you to only build the release version: scons release
envRelease.Alias('release')
envDebug.VariantDir(...)
targetDebug = envDebug.Program(target = 'helloWorld', source = 'helloWorld.cc')
# This makes the debug target get built by default in addition to the release target
envDebug.Default(targetDebug)
# This allows you to only build the debug version: scons debug
envDebug.Alias('debug')
来源:https://stackoverflow.com/questions/15681961/how-to-get-executable-in-debug-mode-using-scons