Scons 如何将对象放入SCON中单独的生成文件夹?
我有一个非常简单的项目:Scons 如何将对象放入SCON中单独的生成文件夹?,scons,Scons,我有一个非常简单的项目: . ├── hello.c ├── lib │ ├── foo.c │ ├── foo.h │ └── SConstruct ├── Makefile └── SConstruct 在构建之后,我希望得到以下信息: . ├── build │ ├── hello │ ├── hello.o │ └── lib │ ├── libfoo.a │ └── foo.o │ ├── config.log ├── hello.c
.
├── hello.c
├── lib
│ ├── foo.c
│ ├── foo.h
│ └── SConstruct
├── Makefile
└── SConstruct
在构建之后,我希望得到以下信息:
.
├── build
│ ├── hello
│ ├── hello.o
│ └── lib
│ ├── libfoo.a
│ └── foo.o
│
├── config.log
├── hello.c
├── lib
│ ├── foo.c
│ ├── foo.h
│ └── SConstruct
├── Makefile
└── SConstruct
我试图补充
VariantDir('build', '.')
但它不起作用。这是我的SConstruct文件
编辑
我还尝试将variant_dir直接添加到SConscript指令:
SConscript(['lib/SConstruct'], variant_dir='build')
但我有一个错误:
$ scons -Q
gcc -o Hello hello.o -Llib -lfoo
/usr/bin/ld: cannot find -lfoo
collect2: error: ld returned 1 exit status
scons: *** [Hello] Error 1
似乎sCONs不再考虑CPPPATH,因为在构建过程中我没有任何Ilib。p> 不要直接使用VariantDir方法,而是使用SConscript调用的variant_dir关键字。为此,最好将源代码移动到单独的src文件夹中,见下面的示例
中的相关章节是分离源目录和构建目录
您还可以在pyconde_2013/examples/exvar文件夹中找到工作示例。阅读上述内容:
env = Environment(CC = 'gcc',
CCFLAGS=['-O2', '-std=c99'],
)
Progress(['-\r', '\\\r', '|\r', '/\r'], interval=5)
# explicitly specify target dir and file base so object
# isn't in source directory.
object = env.Object('build/hello','hello.c')
env.Program('Hello', object,
LIBS=['foo'],
LIBPATH='build/lib/',
CPPPATH=['build/lib']
)
Decider('MD5-timestamp')
VariantDir('build', '.')
SConscript('lib/SConstruct','build/lib')
由于您不想将源文件移动到目录的子目录中,因此SConstruct将使此工作正常,因此您需要手动指定目标目录,这与make的功能一致谢谢您的回答。我已根据你的建议修改了我的问题。我仍然有一些问题。那是因为你的hello目标不在lib文件夹中…所以它不受variant dir设置的影响。这也是为什么我建议首先将所有源文件移动到单独的子文件夹src。这样子文件夹中的所有文件都会受到variant_dir选项的影响就容易多了,所以你并没有真正回答我的问题。我想实现我在问题中提出的要求。我希望所有对象都位于build文件夹中。使用make或cmake很容易做到这一点,我希望SCons也能做到这一点:好的,但您没有提到为达到指定目标而重新组织源代码树实际上是不可能的。从您的另一个问题来看,似乎您正在尝试比较构建工具,以确定SCON是否适合您。如果关于项目结构的相同隐含假设不适用于未来的任何问题,请在前面更清楚地说明这一点。你是对的。我应该把我的问题说得更清楚。相关:我得到这个错误的原因是:**导出不存在的变量build/lib。另一个问题是SCons将源代码复制到构建存储库中,这不是我的目标。
env = Environment(CC = 'gcc',
CCFLAGS=['-O2', '-std=c99'],
)
Progress(['-\r', '\\\r', '|\r', '/\r'], interval=5)
# explicitly specify target dir and file base so object
# isn't in source directory.
object = env.Object('build/hello','hello.c')
env.Program('Hello', object,
LIBS=['foo'],
LIBPATH='build/lib/',
CPPPATH=['build/lib']
)
Decider('MD5-timestamp')
VariantDir('build', '.')
SConscript('lib/SConstruct','build/lib')