我有以下SCons配置:
current_directory
|-<.cpp files>
|-<.h files>
|-SConstruct
|-SConscript
|-bin
|-<empty>
我想构建我的源文件,并将可执行文件和目标文件放入bin
目录。
这就是我在SConstruct
文件中的内容:
SConscript('SConscript', variant_dir='bin', duplicate=0)
在我的SConsript
文件中:
debug_environment.Program(target = 'SsaTest', src_files, LIBS=libraries, LIBPATH=libraries_path)
当我使用scons
命令构建时,我在SsaTest
目录中获取bin
可执行文件(根据需要),但目标文件保留在当前目录中。
如何在.o
目录中构建bin
个文件?
非常感谢。
编辑:完成SConscript
个文件(原谅我xxx
s)
import os
# This is correctly Exported()
Import('debug_flags')
# Paths to header files
headers_paths = ['#/../../xxx/include/',
'#/../../../xxx/include/',
'#/../../xxx/include/',
'#/../../xxx/include/',
'#/../../xxx/include/']
# Path to source files
src_folder = '#./'
# Source files list
src_files = ['xxx.cpp',
'xxx.cpp',
'xxx.cpp',
'xxx.cpp',
'xxx.cpp']
# Prepend the relative path to each source file name
src_files = [src_folder + filename for filename in src_files]
libraries = ['xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx']
libraries_path = ['#/../../xxx/lib',
'#/../../../xxx/bin',
'#/../lib',
'#/../../xxx/lib',
'#/../../xxx/lib',
'#/../../xxx/lib']
# Debug environment
debug_environment = Environment(CC = 'g++', CCFLAGS=debug_flags, ENV = os.environ, CPPPATH=headers_paths);
# Executable build command
debug_environment.Program(target = 'SsaTest', src_files, LIBS=libraries, LIBPATH=libraries_path)
答案 0 :(得分:2)
对于不推荐的源文件使用'#',因为你有你的情况,scons无法使用variant dirs正确处理它,以及结果如何在放置源的目录中创建目标文件。
所以,我尝试用相同的配置构建你的例子并且没有麻烦:
#SConsctruct
SConscript('SConscript', variant_dir='bin', duplicate=0)
#SConscript
src_files = Glob('*.cpp')
debug_environment = Environment()
debug_environment.Program('SsaTest', src_files)
因此,所有目标文件都在bin目录中生成。
最后,您对源文件的关系目录没有麻烦,然后使用变量目录。但是包括dirs取决于变体dirs。 配置例如:
build
app
--SConscript
--src
----*.h
----*.cpp
SConstruct
#SConstruct
rootEnv = Environment()
Export('rootEnv')
SConscript('app/SConscript', variant_dir='build', duplicate=0)
你SConscript看起来会像这样:
Import('rootEnv')
env = rootEnv.Clone()
env.Append(CPPPATH = ['#app/src'])
env.Program('app', Glob('src/*.cpp'))
'#app / src' - 其中#在使用variant dir时非常重要,因为如果是app / src,build命令将会显示:' - Ibuild / app / src'(在包含路径之前添加变量dir) 。但添加'#'命令将正确显示:' - Iapp / src'。
答案 1 :(得分:1)
SConscript中突出的一点是你如何使用#./
将每个源文件的路径前置。
# Path to source files
src_folder = '#./'
为什么在该路径中使用点,不是必需的?尝试使用以下#/
,就像使用其他路径一样:
# Path to source files
src_folder = '#/'
另一种选择是将源文件和相应的SConscript放在它自己的子目录中。它不清楚为什么你有一个SConstruct,SConscript和源文件都在一个目录中。创建一个子目录,或者如果没有必要,可以考虑删除SConscript。
在SConstruct中的SConscript()函数调用中,将variant_dir称为“#bin”而不是“bin”。不确定这是否有帮助,但更好的做法。
在使用Repository()SCons函数引用源文件之前,我已经看到过这种行为here。
此外,这是偏离主题的,但如果您的包含和库路径(headers_paths和libraries_path变量)不在项目目录结构中,您可以考虑使用绝对路径。我个人认为使用具有多个../
路径的相对路径非常难看。