为什么SCons VariantDir()不将输出放在给定目录中? [英] Why does SCons VariantDir() not put output in the given directory?

查看:202
本文介绍了为什么SCons VariantDir()不将输出放在给定目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将 SCons 用于新项目.看起来确实不错,尽管我发现VariantDir相当令人困惑.

I'm thinking about using SCons for a new project. It looks really good, though I'm finding VariantDir quite confusing.

我有一个简单的项目,在一个目录中有少量C源文件,我想以普通"模式和配置文件"模式进行构建-为gcc提供两组不同的选项.我希望输出分别进入normal/和profile/目录.

I have a simple project with a handful of C source files in one directory, and I want to build in "normal" and in "profile" mode -- with two different sets of options to gcc. I want the outputs to go in the normal/ and profile/ directories, respectively.

为了进行测试,我只缩减了一个源文件t.c,其中包含main().我的SConstruct文件位于同一目录中,如下所示:

For testing, I've cut back to just a single source file, t.c, which has a main() in it. My SConstruct file is in the same directory, and looks like this:

normal = DefaultEnvironment(tools=['mingw'], CCFLAGS = '-O2')
normal.VariantDir('release', '.', duplicate=0)
normal.Program('t', ['t.c'])

#profile = normal.Clone(CCFLAGS='-O2 -pg', LINKFLAGS = '-pg')
#profile.VariantDir('profile', '.', duplicate=0)
#profile.Program('t', ['t.c'])

当我运行scons时,我希望它可以将t.o和t.exe放入release/,但会将它们放在当前目录中.而且我根本无法在没有注释的3条配置文件行的情况下运行它-如果我这样做了,则会出现此错误:

When I run scons, I'm expecting it to put t.o and t.exe into release/, but it puts them in the current directory. And I can't run it at all with the 3 profile lines uncommented -- if I do, I get this error:

scons:***为同一目标指定了两个具有不同操作的环境:t.o

基本上,我不确定为什么我的VariantDir()调用没有告诉scons将输出放入指定的输出目录release.

Basically, I'm unsure why my VariantDir() calls aren't telling scons to put the output in the specified output directory, release.

(我已经在文档和新闻组中读到了相当多的内容,但没有任何答案可以回答这个问题.我最近到达的是

(I've read a fair bit in the docs and newsgroups, but nothing that answers this question. The closest I've come is this page, which describes a similar thing, but it involves a separate src/ directory and two separate scons files, and importing/exporting variables between them. That doesn't seem pleasant.)

推荐答案

是的,VariantDir在scons中令人困惑.尽管宣传不佳,但您可以将SConstruct和SConscript都放在同一目录中,使用当前目录作为源目录

Yes, VariantDir is confusing in scons. Although not well advertised, you can put both SConstruct and SConscript in the same directory, using the current directory as the source directory

# SConstruct
SConscript('SConscript', build_dir='build', src='.')

# SConscript
Program('main.c')

我一直没有找到一种避免使用两个文件的方法,同时保持理智地试图理解变体dir:)

I have never found a way to avoid using two files while keeping my sanity trying to understand variant dir :)

这篇关于为什么SCons VariantDir()不将输出放在给定目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆