如何将对象放入SCONS中的分离的构建文件夹中



我有一个非常简单的项目:

.
├── 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文件

env = Environment(CC = 'gcc',
    CCFLAGS=['-O2', '-std=c99'],
)
Progress(['-r', '\r', '|r', '/r'], interval=5)
env.Program('Hello', 'hello.c',
    LIBS=['foo'],
    LIBPATH='lib/',
    CPPPATH=['lib']
)
Decider('MD5-timestamp')
VariantDir('build', '.')
SConscript(['lib/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

似乎SCON不再考虑CPPPATH,因为在构建过程中我没有任何-Ilib

不要直接使用VariantDir()方法,而是variant_dir呼叫的CC_7关键字。为此,将您的源转移到一个单独的" src"文件夹中是一个好主意(请参见下面的示例(。

用户指南中的相关章节是15个"分开源和构建目录"。

您还可以在pyconde_2013/examples/exvar文件夹中的https://bitbucket.org/dirkbaechle/scons_talks找到一个有效的示例。

从阅读上述:

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

由于您不想将源文件移动到目录的子范围中,因此您需要手动指定目标目录(这与Make的功能一致(

最新更新