From SwinBrain

SCons is a software build system written in Python. Because build scripts are written in python SCons makes some tasks much easier would be in simpler build system – one example the particularly demonstrates this strength is building cross platform software.

SCons also differs from alternatives like make by offering in-built dependency checking as well as being (arguably) more readable than Ant’s XML.

Although SCons can be used with a variety of languages and platforms this article is aimed at C++ developers on Windows. The examples were tested with the Microsoft Visual Studio 2005 C++ Compiler, and an express edition of Visual Studio (with the compiler) is available free from Microsoft.


Getting Started

  1. Download and install python
  2. Download SCons. Windows users should install the .msi (Microsoft Installer) version.


The following C++ code should be saved as main.cpp in your working directory.

  1. #include <iostream>
  3. int main()
  4. {
  5. std::cout << "hello world" << std::endl;
  6. return 0;
  7. }

Save the following file as SConstruct (no extension) in your working directory.

  1. import os
  2. import sys
  4. env = Environment(ENV = os.environ,
  5. CPPFLAGS = '/EHac /MDd')
  6. env.Program('helloworld', 'main.cpp')
  • Line 4 specifies that the default environment variables supplied by the operating system contains enough information to find the compiler
  • Line 5 specifies the relevant compiler flags. Note that the Microsoft compiler will generate large numbers of warnings for builds that do not specify some compilation options – for this simple example it is sufficient to enable exception handling (/EHac) and specify the Multi-threaded debug dll runtime (/MDd).
  • Line 6 creates a program named 'helloworld.exe' on Windows, from the source file 'main.cpp'

To compile using SCons

  1. Open the Microsoft Visual Studio command prompt (Menu: Start->Program Files->Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt).
  2. Change to your working directory
  3. Type scons



The compiled files can be removed by typing 'scons -c'

Tool Support

SCons has inbuilt support for a wide range of programming languages and tools. Adding support for additional tools is reasonably easy.

  • C/C++
  • Java
  • Fortran
  • TeX/LaTeX
  • Flex and Bison or Lex and Yacc


Additional documentation for SCons is available from