I have the following SCons configuration:
current_directory
|-<.cpp files>
|-<.h files>
|-SConstruct
|-SConscript
|-bin
|-<empty>
I want to build my source files and put the executable and the object files into the bin directory.
This is what I have in my SConstruct file:
SConscript('SConscript', variant_dir='bin', duplicate=0)
While in the SConsript file I have:
debug_environment.Program(target = 'SsaTest', src_files, LIBS=libraries, LIBPATH=libraries_path)
When I build using scons command I get the SsaTest executable in the bin directory (as desired), but the object files are left in the current directory.
How can I have the .o files be built in the bin directory as well?
Many thanks.
EDIT: Complete SConscript file (forgive me for the xxxs)
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)
Using ‘#’ with source files not recommended, because you have your situation, scons can’t correctly process it with variant dirs and how result create object files in directory where sources placed.
So, i tryed to build your example with same configuration and have no troubles:
So, all object files are generated in bin directory.
Finally, you have no troubles with relation dirs with sources files then using variant dirs. But include dirs are depended from variant dirs.
Configuration for example :
You SConscript will be looking like it:
‘#app/src’ – where # is very important when using variant dir, because if would be app/src, build command will be looking: ‘-Ibuild/app/src’ (adding variant dir before include path). But adding ‘#’ command will be looking correctly : ‘-Iapp/src’.