Click here to Skip to main content
14,972,891 members
Articles / Containers / Virtual Machine
Posted 7 Jun 2009


48 bookmarked

Setting up an Open Source tool chain

Rate me:
Please Sign up or sign in to vote.
4.67/5 (13 votes)
12 Jun 2009CPOL7 min read
This article shares my experiences setting up an Open Source tool chain for developing C++ applications.


This article describes the steps I have taken to set up an Open Source tool chain I use to write C++ programs.

In it, I show how I:

  • Set up a text editor with code highlighting
  • Set up a Unix style environment required to build and compile C++ applications
  • Set up a C/C++ compiler
  • Create and compile a Hello World C++ program using a make file


A while back, I decided to share the source code for an application I developed. I had written the program using Microsoft C++, Visual Studio, and made heavy use of MFC. I found that there was a pool of people who would be willing to help, but they were unable to help because they didn't have Microsoft C++. For this reason, I started investigating alternatives to using proprietary tools, and in this article, I share my experiences.

A secondary reason for writing this article is that I want to write further articles about other technologies I have found out about. This article will allow people to know the tool chain I use so they can follow further articles.

Prerequisites for following this tutorial

To write this tutorial, I have started off with a clean install of Windows XP Home edition. I am actually using a VMware virtual machine for this. The tutorial should work on most Windows versions.

Download and install Notepad++

Notepad++ is an Open Source text editor that includes features like tabbed browsing and syntax highlighting. It is also customizable which will allow me to add menu items to compile and run the programs with one click.

Download the latest version at I downloaded npp.5.4.3.Installer.exe.

Setting it up is easy, and I used all the defaults so I won't go through the steps here. You can check Notepad++ works by running the application which should be in your Program Files menu.

Note: If you want to find out more about Notepad++, the website is

Download and install MinGW

This is the actual compiler tool chain.

Install this using the auto installer

I selected options as follows:

  1. Download and install
  2. Current version
  3. Full initialization (you must install the base tools, G++, and make as a minimum, but I recommend installing everything)

For everything else, I use the default settings.

Download and install MSYS

Although not strictly necessary, I use MSYS. This is a minimal Unix style SYStem for Windows, and it sets up a Linux like environment on a Windows machine. I download and use various libraries with my programs (zipping libraries, GTK+, MySQL libraries etc.) and the make files frequently contain Unix commands. The main example is the make clean section which uses rm rather than del. MinGW will make using these a lot easier.

Go to You can select the current release section, and it will expand to show the current release. I downloaded MSYS-1.0.10.exe.

I installed it with all the default setup and options.

Note: If you want to find out more about MSYS and MinGW, the website is

Set up Environment Variables

We need the MinGW bin directory and the MSYS bin directory to be in the path. To do this, go to Control Panel -> System -> Advanced tab -> Environment Variables button. Under the system variables section, find the path variable and press Edit. Add the MinGW directory to the end. (Addresses are separated by ; so I need to add ;C:\MinGW\bin;C:\msys\1.0\bin on my system.)

While you are there, add a user variable called HOME and set it to the value C:\msys\1.0\home\<<WINDOWS USER NAME>>.

Note: Don't surround the path with "'s. This will cause make to not find the directory. (Although the normal shells will.)

Check if this has worked by running the command prompt and typing gcc --help. If you get a command not found error, it means the path is not correctly set up.

Set up a C/C++ compiler

Finally, we are ready to get our first program together and compiled. Load up MSYS by clicking the blue M icon. (I usually put it in my quick launch for convenience.) Follow these steps:

Note: You can copy the command from here and press shift + INS in MSYS to run it

Make a code directory:

  • cd /c/
  • mkdir code

Make a directory for our Hello World application:

  • cd /c/code/
  • mkdir hello_world

Create the C++ program:

  • "/c/program files/notepad++/notepad++.exe" /c/code/hello_world/main.cpp
  • Paste in the following code, then save and close Notepad++:
#include <iostream>

int main( int argc, char *argv[] )
    printf("Hello World\n");
    return 0;

Careful copying this code. <'s may be turned into &lt; and >'s may be turned into &gt;.

Don't forget the newline at the end of the file.

Create the Makefile:

  • "/c/program files/notepad++/notepad++.exe" /c/code/hello_world/makefile
  • Paste in the following code, then save and close Notepad++:
$(warning Starting Makefile)


main.exe: main.cpp
    $(CXX) main.cpp -o main.exe

    -rm main.exe

Test the setup by making and running the program:

  • cd /c/code/hello_world/
  • make
  • ./main.exe

You should see the text Hello World appear when the program has run.

Finally, check the clean up works OK:

  • cd /c/code/hello_world/
  • make clean

You should see that the exe file has gone.

Setting up the Compile and Run commands in Notepad++

We can set up Notepad++ shortcuts. First, create two batch files using these steps:

  • "/c/program files/notepad++/notepad++.exe" /c/code/run.bat
  • Paste in the following code, then save and close Notepad++:
:##BATCH to run fron notepad++
cd %1
  • "/c/program files/notepad++/notepad++.exe" /c/code/run_clean.bat
  • Paste in the following code, then save and close Notepad++:
:##BATCH to run fron notepad++
cd %1
make clean

Now, we can set up Notepad++ to run these batch files:

  • Load Notepad++
  • Press F5
  • Enter c:\code\run.bat $(CURRENT_DIRECTORY)
  • Save the command as RUN CODE
  • Press F5
  • Enter c:\code\run_clean.bat $(CURRENT_DIRECTORY)
  • Save the command as CLEAN

All done - so what have we got?

We now have a tool chain set up. The directory c:\code contains the programs and we can create a sub directory for new programs. Each sub directory will need a makefile and the program files. The makefile can be changed depending on what program files are needed. You can use Notepad++ for editing, and use the RUN CODE menu option to make and run the program. The run code command will run make in the directory the current file in Notepad++ is running.

This may all seem pretty simple and not worth an article, but I plan to write more articles and need to share how my system is set up for them to make sense.

Articles (so far) using this

Points of interest

Make file notes

  • When changing the makefile, you should use the make clean option. Normally, the make program will automatically check which commands it needs to run based on file modified dates. This won't work when you are changing the makefile, so you can use the make clean option to force it to re-run.
  • Make is a very powerful system for constructing programs. I have included a simple make script that works, but make scripts can also be more advanced. You can configure for DEBUG and RELEASE builds. I used to let my compiler tools create make files for me, but I have found that hand crafting them has forced me to learn a lot about the build process, and I now understand error messages in the build process much better.


This is the process I have used to set up this tool chain. I am interested in hearing from anyone who tries to follow these steps and hear about your experiences. If you can help me change the instructions to make it easier for others, that would be great. I am also interested to know what people think about the way I have setup my tool chain. It's always good to learn more and improve the way you do things.


  • 07-Jun-2009 - First version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

GeneralAttention Newbies ... Why you got my 5 Pin
programmersmind6-Jul-09 19:12
Memberprogrammersmind6-Jul-09 19:12 
GeneralI can't change this anymore Pin
metcarob24-Jun-09 8:42
Membermetcarob24-Jun-09 8:42 
GeneralMake files are horrible and time sucking Pin
visualc9-Jun-09 1:43
Membervisualc9-Jun-09 1:43 
GeneralRe: Make files are horrible and time sucking Pin
metcarob10-Jun-09 9:55
Membermetcarob10-Jun-09 9:55 
GeneralRe: Make files are horrible and time sucking Pin
Jim Crafton16-Jun-09 3:37
MemberJim Crafton16-Jun-09 3:37 
GeneralFreebees Pin
geoyar8-Jun-09 15:49
professionalgeoyar8-Jun-09 15:49 
GeneralRe: Freebees Pin
PedroMC8-Jun-09 23:13
MemberPedroMC8-Jun-09 23:13 
GeneralRe: Freebees Pin
geoyar9-Jun-09 5:25
professionalgeoyar9-Jun-09 5:25 
GeneralRe: Freebees Pin
PedroMC9-Jun-09 23:51
MemberPedroMC9-Jun-09 23:51 
GeneralRe: Freebees Pin
metcarob10-Jun-09 9:56
Membermetcarob10-Jun-09 9:56 
GeneralRe: Freebees Pin
PedroMC11-Jun-09 0:05
MemberPedroMC11-Jun-09 0:05 
GeneralA better way. Pin
Andrew Maclean8-Jun-09 14:07
MemberAndrew Maclean8-Jun-09 14:07 
GeneralNice article but Pin
Jim Crafton8-Jun-09 4:41
MemberJim Crafton8-Jun-09 4:41 
GeneralRe: Nice article but Pin
metcarob8-Jun-09 11:10
Membermetcarob8-Jun-09 11:10 
GeneralRe: Nice article but Pin
Jim Crafton8-Jun-09 11:16
MemberJim Crafton8-Jun-09 11:16 
GeneralAn alternative [modified] Pin
Jim Xochellis7-Jun-09 22:29
MemberJim Xochellis7-Jun-09 22:29 
GeneralRe: An alternative Pin
metcarob8-Jun-09 11:11
Membermetcarob8-Jun-09 11:11 
GeneralRe: An alternative Pin
Spatlabor9-Jun-09 0:10
MemberSpatlabor9-Jun-09 0:10 
GeneralWhy my 5 Pin
DaTxomin7-Jun-09 13:55
MemberDaTxomin7-Jun-09 13:55 
GeneralRe: Why my 5 Pin
metcarob8-Jun-09 11:13
Membermetcarob8-Jun-09 11:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.