【问题标题】:How to get executable in debug mode using scons如何使用 scons 在调试模式下获取可执行文件
【发布时间】:2016-06-23 19:30:41
【问题描述】:

我正在使用 scons 用 vc10 和 Renesas 编译器进行编译。

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

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

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

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

【问题讨论】:

    标签: scons


    【解决方案1】:

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

    env = Environment()
    env.Append(CXXFLAGS = ['/DEBUG'])
    

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

    要使用目标,您可以执行以下操作:

    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() 函数的指定构建调试版本。

    另一种方法是使用命令行参数,例如:scons debug=0scons debug=1,这将允许您在构建脚本中执行一些逻辑,从而让您更轻松地控制 variant-dir等,如下:

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

    查看here 了解更多命令行处理选项。

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

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

    【讨论】:

    • 我认为你需要在上面的variantdir版本中的debug变体中添加/DEBUG标志?
    • 似乎对我不起作用,我将/DEBUG 附加到调试环境中,它仍然说它无法加载任何调试符号。
    猜你喜欢
    • 2022-07-01
    • 1970-01-01
    • 2018-01-13
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2011-05-09
    • 2014-01-15
    相关资源
    最近更新 更多