在调试模式下获得可执行文件

在调试模式下获得可执行文件

本文介绍了如何使用 scons 在调试模式下获得可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 scons 与 vc10 和 renesas 编译器进行编译.

I am using scons to compile with vc10 and renesas compiler.

是否有任何命令可以在调试模式下获取可执行文件?

Is there any commands to get an executable in debug mode?

如果我使用命令scons and enter"执行我的项目,它将进入发布模式.

If I executed my project with the command "scons and enter" it is going to release mode.

我无法使用 Visual Studio 调试器调试该 .exe 文件.

I am unable to debug that .exe file using the visual studio debugger.

谁能告诉我如何在调试模式下获得调试可执行文件?scons 中有没有要设置的命令或标志?

Can anyone tell me how to get the debugging executable in debug mode?Is there any commands or flags to set in scons?

推荐答案

要在调试模式下获取可执行文件,只需将适当的编译器调试标志添加到 CXXFLAGS 构造变量中,如下所示:

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'])

但这是相当基本的,我想您可能希望能够通过命令行控制何时在调试模式下编译可执行文件.这可以通过命令行目标或命令行选项(如 debug=1)来完成

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)

如果您在没有命令行目标的情况下执行 SCons,那么将按照 envRelease.Default() 函数的指定构建发布版本.如果您使用调试目标执行 SCons,如下所示:scons debug 那么调试版本将按照 envDebug.Alias() 函数的指定构建.

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.

另一种方法是使用命令行参数,例如:scons debug=0scons debug=1,这将允许您执行一些逻辑在您的构建脚本中,从而使您可以更轻松地控制变体目录等,如下所示:

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.

我更喜欢的最后一个选择是始终构建两个版本,每个版本都在各自的变体目录中(例如 build/vc10/release 和 build/vc10/debug).

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')

这篇关于如何使用 scons 在调试模式下获得可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:16