SCons
SCons is a build system.
Installation
Ubuntu 16.04
You can install scons with:
However…
The default scons provided by 16.04 (xenial) is very out-of-date (v2.4.1). You can get the latest scons (v3.0.1) as of Mar 2018) by first adding the following line to /etc/apt/sources.list:
And then install scons with the command:
Basic Hello, World Example
Prerequisites
- scons is installed on your system
Steps
-
Create a new folder called “HelloProject”. All following files in this example will be created in this folder.
-
Create a file called main.cpp with the following content:
-
Create a file called sconstruct (no file extension) with the following content:
env = Environment() hello = Program([“hello.cpp”])
-
From the console, run scons in the current folder:
-
This should start the build process and produce an executable called hello. Run the executable with the following command:
-
Finished!
Importing And Exporting
scons variables may be shared between sconscript files through importing, _exporting _and returning.
Before you can import a variable, it must be exported. You can do this by calling Export() and providing it with a space-separated string of all the variables you wish to export:
Export(‘env installDir’)
You can then import this from a different Sconscript file:
Import(‘env installDir’)
You can return a single object from a Sconscript with the Return() function:
Return(‘myLib’)
The can be captured in the calling Sconscript file with:
myLib = Sconscript(‘src/mySubSconscript’)
Building
By default, scons does not perform an out-of-source build. You can perform an out-of-source build by including the following line in your root-level sconstruct file:
where src/MyApp.scons
points to a child scons file.