Building with SCons
suggest changeYou can build the cross-platform “Hello World” C++ code, using Scons - A Python-language software construction tool.
First, create a file called SConstruct
(note that SCons will look for a file with this exact name by default). For now, the file should be in a directory right along your hello.cpp
. Write in the new file the line
Program('hello.cpp')
Now, from the terminal, run scons
. You should see something like
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o hello.o -c hello.cpp
g++ -o hello hello.o
scons: done building targets.
(although the details will vary depending on your operating system and installed compiler).
The Environment
and Glob
classes will help you further configure what to build. E.g., the SConstruct
file
env=Environment(CPPPATH='/usr/include/boost/',
CPPDEFINES=[],
LIBS=[],
SCONS_CXX_STANDARD="c++11"
)
env.Program('hello', Glob('src/*.cpp'))
builds the executable hello
, using all cpp
files in src
. Its CPPPATH
is /usr/include/boost
and it specifies the C++11 standard.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents