Build C++ Programs With SCons in Eclipse Using SConsBuilder Plugin(MS Windows)
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
- 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.
- 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 binaries for Windows.
Run the installer to install it. I will assume that we have installed it in C:\Python25 directory.
- Now we are ready to install the SCons build tool. Download the windows installer from SCons website and run the installer to install it.
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)
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
- 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:
- Go to Help -> Software Updates -> Find and Install..
- Choose “Search for new features to install”.. and click “Next”
- Click the “New Remote Site..” button
- 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
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.
- Next we need to configure the SCons plugin in Eclipse. To do so, go to Window -> Preferences -> C++ -> SCons.
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.
- 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).
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.
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.
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.
- 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.
Comments are closed.