Why does SCons VariantDir() not put output in the given directory?

让人想犯罪 __ 提交于 2019-12-01 03:52:21

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

and

# SConscript
Program('main.c')

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

I was able to separate binaries in a build directory using this call:

# SConstruct
SConscript('SConscript', variant_dir='build', src_dir='..', duplicate=0)

If you want to put binaries into a directory two levels below, do this:

# SConstruct
SConscript('SConscript', variant_dir='build/release', src_dir='../..', duplicate=0)

Basically, provide the src_dir parameter as a path from your build directory back to your source directory.

As http://www.scons.org/wiki/VariantDir%28%29 said,

Note that when you're not using an SConscript file in the src subdirectory, you must actually specify that the program must be built from the build/hello.c file that SCons will duplicate in the build subdirectory.

VariantDir('release','.',duplicate=0)
env=Environment()
env.Program('release/t',['release/t.c'])

when I run it with scons on Linux.

scons -u . 
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: release
gcc -o release/t.o -c t.c
gcc -o release/t release/t.o
scons: done building targets.

I guess it would also work on Win32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!