如何使用Scons与Glob在不同环境下编译相同的对象?
我有一个使用 Scons 构建的 C++ 项目。起初我只有优化版本来编译,它工作得很好。然后我还需要一个调试版本,然后我为其添加另一个环境。这是 Scons 代码:
env = Environment()
opt = env.Clone(CCFLAGS=['-pthread', '-O3', '-Wall'])
opt_objs = opt.Glob('src/*.cpp')
prog = opt.Program('prog', opt_objs)
dbg = env.Clone(CCFLAGS=['-pthread', '-Wall', '-g', '-O0'])
dbg_objs = dbg.Glob('src/*.cpp')
dbg_prog = dbg.Program('dbg_prog', dbg_objs)
使用此代码,我遇到了错误:
scons: *** Two environments with different actions were specified for the same target:
src/CometReadService.o
如您所见,这些 .o 文件目标由 opt.Glob('src/.cpp') 和 dbg.Glob('src/< /em>.cpp') 完全相同的名称。通过阅读文档多个构建环境我知道我可以将对象重命名为“opt.Object('xxx-opt', 'xxx.c')”,但是,它是 Glob 而不是 Object。我该如何解决这个问题?
I have a C++ project builds with Scons. At first I have only the optimized version to compile, it works fine. Then I also need a debug version, then I add another environment for it. Here is the Scons code:
env = Environment()
opt = env.Clone(CCFLAGS=['-pthread', '-O3', '-Wall'])
opt_objs = opt.Glob('src/*.cpp')
prog = opt.Program('prog', opt_objs)
dbg = env.Clone(CCFLAGS=['-pthread', '-Wall', '-g', '-O0'])
dbg_objs = dbg.Glob('src/*.cpp')
dbg_prog = dbg.Program('dbg_prog', dbg_objs)
With this code, I ran into error:
scons: *** Two environments with different actions were specified for the same target:
src/CometReadService.o
As you can see, those .o files targets created by opt.Glob('src/.cpp') and dbg.Glob('src/.cpp') exactly same name. By reading the document Multiple Construction Environments I know I can rename the object like "opt.Object('xxx-opt', 'xxx.c')", but however, it is Glob not Object. How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
scons 手册介绍了如何使用
VariantDir< /code> 函数(或添加 SConscripts 时的参数)来设置不同的构建目录。最简单的是,VariantDir 将构建输出与源文件分开,但它也可用于分隔不同环境的构建输出。
使用 VariantDir 需要进行一些实验。例如,请注意 Glob 参数已更改 - 如果没有
duplicate=0
参数,VariantDir 的默认行为是复制构建目录中的源文件。The scons manual describes how to use the
VariantDir
function (or argument when adding SConscripts) to set up different build directories. At its simplest, VariantDir separates the build output from the source files, but it can also be used to separate the build output of different environments.Using VariantDir can take some experimentation. For instance, note that the Glob argument has changed -- without the
duplicate=0
parameter, the default behavior is for VariantDir to duplicate the source files in the build directory.