Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(‘The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

October 24, 2007

Build C++ Programs With SCons in Eclipse Using SConsBuilder Plugin(MS Windows)

Filed under: C++, Eclipse — tabrez @ 9:13 pm

By the end of this post, you will be able to create C++ projects in the Eclipse IDE and build them using the SCons build tool. SCons is an alternative build tool to GNU make/Makefiles. You can read more about SCons on its website(and ask yourself why are you reading this post in the first place!).

Install MinGW, Eclipse CDT, Python and SCons on Windows

  1. Skip this step if you have a working Eclipse for C++ installation.

    If the MinGW toolchain is not already installed on your Windows system, download and install MinGW, MSYS and gdb debugger from MinGW’s download page. Similarly download and install the latest version of Eclipse for C++(Europa) if it’s not already installed. If you are willing to take my recommendation, I suggest you start with EasyEclipse for C++ IDE which comes with many useful C++ plugins pre-installed. When you install EasyEclipse/Eclipse Europa for C++, it will automatically detect the MinGW installation and will configure all paths properly, but if for some reason you come across any problem(or if you are using an older version of Eclipse), take a look at my earlier post on how to configure MinGW with Eclipse IDE.

    Alternatively you can download and install the Wascana Desktop Developer which comes with Eclipse Europa, CDT plugin, MinGW toolchain (among other things) all integrated together as one piece. Read my post about the Wascana IDE for more information.

  2. Skip the step if you already have a working Python installation.

    I am assuming that Eclipse CDT and C++ development toolchain(MinGW) are properly setup on your system. Before we can go ahead and install the SCons build tool, we need to install Python first, as SCons depends on a working Python installation. Download your favourite Python distribution for Windows and install it. I use Python from the python.org website but feel free to use any implementation that you like, such as ActivePython.

    Download Python for Windows

    Download Python binaries for Windows.
    Run the installer to install it. I will assume that we have installed it in C:\Python25 directory.

  3. Now we are ready to install the SCons build tool. Download the windows installer from SCons website and run the installer to install it.

    Download SCons for Windows

    SCons installer will automatically detect the location where Python is installed during installation. After the installer is finished, you can start building C++ programs using SCons from the command-line. In fact, it would be a good idea to do a few checks to make sure that everything we have done until now is setup properly. On the windows command prompt, run the following:

    C:\> python -V
    C:\> scons -v

    (note the uppercase V for the python command)

    Verify if Python and SCons are installed

    You can further create a sample C++ program along with an SConstruct build file and try building from the command-line using the scons tool. Proceed to the next step if everything works out as expected.


Installing and Configuring SConsBuilder plugin in Eclipse

  1. We need to install the SCons plugin in Eclipse now. The installation procedure is explained on the SConsBuilder web page but I will repeat those instructions here for convenience:
    1. Go to Help -> Software Updates -> Find and Install..
    2. Choose “Search for new features to install”.. and click “Next”
    3. Click the “New Remote Site..” button
    4. Enter “SCons Build” or something like that in the “Name” field and enter http://nic-nac-project.de/~lothar/eclipse/update/ in the “URL” field

    Specify Remote URL for SConsBuilder Eclipse plugin

    You may be interested in having a look at the documented feature list of this plugin. You can confirm the installation of SConsBuilder plugin from Help -> About -> Plug-in Details.

  2. Next we need to configure the SCons plugin in Eclipse. To do so, go to Window -> Preferences -> C++ -> SCons.

    Configure the SConsBuilder preferences in Eclipse IDE

    Enter the values as you see in the above screenshot. No other field matters to us right now except for the first one(‘SCons executable’) but you need to give valid values in all of them; which means that even if you have no intention of using CppUnit, you still need to make sure that the text fields in its section(CppUnit include and library directories) have valid values(any valid path will do). Of course, when using CppUnit, you need to check the “Use CppUnit” checkbox and enter the correct include and library paths in its fields.

    Restart Eclipse if you are prompted to.

  3. We are almost done here! Now create a C++ project from File -> New Project and select one of the templates from the New Project window, say “Empty Project”. Try not to select any Makefile related project templates though, as we will be using SCons as our build tool. After the project is created we can convert it to an SCons project by going to File -> Other -> C++ -> Convert to SCons Project(search around if it’s not there, it may be present in a different category in your Eclipse distribution).

    Convert C++ project to SCons project in Eclipse

    Note: To remove the SCons nature from the project, follow the same menus: File -> Other -> Convert to SCons Project.

    You will see a new file created in your Project view called SContruct which you might identify as the SCons build script.

    SCons project generates SConstruct file

    I remove the default generated code in the SConstruct file and type my own build instructions in it. The other thing you can notice are the new build command menu items in the project context menu(I couldn’t find any other way to access these build commands). Right-click on the project to see it.

    SConsBuilder build commands in the context menu in Eclipse IDE

    Select “SCons Build” from the available build commands in the context menu and your C++ project should be built using the SCons build tool using the instructions provided in the SConstruct file. You can now continue adding more C++ source files, more directories and SConscript build files.

Troubleshooting?

  • Verify if you can compile C++ programs in Eclipse before starting with any SCons stuff. This would help find out if MinGW is properly configured with Eclipse. See this post for help. (You may be using Cygwin toolchain, I am just taking MinGW as an example.)
  • Make sure that you install Python and SCons at locations that do not contain space(s) in their paths. This is not always required but it is a good rule to follow anyway.
  • Make sure that running ‘python -V’ and ’scons -v’ on the command-line returns some output and not an error.
  • Make sure that all the fileds on SCons preference page have valid values. Use the screenshot shown above for guidance.

SConsBuilder plugin for Eclipse is not the perfect solution for working with SCons; instead it only barely gets the job done. In the absence of any other better alternatives, all we can do is to hope and pray that the plugin gets more love from its developers and improves with the time.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Wascana is Eclipse Based Standalone C++ IDE for MS Windows
  • How to Test C++ Boost Installation
  • C++ Development Environment on Windows using Eclipse Ganymede and Nuwen MinGW
  • Unit Testing C++ Programs using CppUnit in Eclipse IDE on Windows
  • Java on Gentoo
  • Develop Ruby Applications Using Eclipse IDE
  • Develop Ruby Applications Using SciTE Editor


  • No Comments »

    No comments yet.

    RSS feed for comments on this post. TrackBack URI

    Leave a comment


    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost