如何使用Scons与Glob在不同环境下编译相同的对象?

发布于 2024-09-28 22:55:22 字数 850 浏览 5 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-10-05 22:55:22

scons 手册介绍了如何使用 VariantDir< /code> 函数(或添加 SConscripts 时的参数)来设置不同的构建目录。最简单的是,VariantDir 将构建输出与源文件分开,但它也可用于分隔不同环境的构建输出。

env = Environment()

opt = env.Clone(CCFLAGS=['-pthread', '-O3', '-Wall'])
opt.VariantDir('gen-opt', 'src', duplicate=0)
opt_objs = opt.Glob('gen-opt/*.cpp')
prog = opt.Program('prog', opt_objs)

dbg = env.Clone(CCFLAGS=['-pthread', '-Wall', '-g', '-O0'])
dbg.VariantDir('gen-dbg', 'src', duplicate=0)
dbg_objs = dbg.Glob('gen-dbg/*.cpp')
dbg_prog = dbg.Program('dbg_prog', dbg_objs)

使用 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.

env = Environment()

opt = env.Clone(CCFLAGS=['-pthread', '-O3', '-Wall'])
opt.VariantDir('gen-opt', 'src', duplicate=0)
opt_objs = opt.Glob('gen-opt/*.cpp')
prog = opt.Program('prog', opt_objs)

dbg = env.Clone(CCFLAGS=['-pthread', '-Wall', '-g', '-O0'])
dbg.VariantDir('gen-dbg', 'src', duplicate=0)
dbg_objs = dbg.Glob('gen-dbg/*.cpp')
dbg_prog = dbg.Program('dbg_prog', dbg_objs)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文