Building with SCons

suggest change

You 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


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.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.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents