Articles in this series:

You can easily find a million articles out there discussing compiler nuances, weighing the pros and cons of various data structures or discussing the optimization of databases. Those sorts of articles are fascinating reads for advanced programmers but completely leave in the dust many others. Others asking very basic questions such as ‘How do I use a compiler?’ or ‘How can I code without an IDE?’ These basic questions deserve good answers because they represent the absolute first step that everyone has to take before they can become a veteran programmer: setting up a development environment.

Many new programmers today are not taught how to work with code outside of a strict framework provided by their elders - generally an Integrated Development Environment (IDE) of some sort. Java is one of the more popular introductory languages these days and for the most part, no one develops in Java without an IDE (even though there are plenty of differing opinions as to which IDE is superior). Other languages are following suit - C# doesn’t often stray away from Visual Studio, for example. Meanwhile, if you ask the question ‘What IDE do you use?’ to a variety of C programmers you’ll get a wide variety of answers - some of which will be ‘None’. But C is no longer a the preferred choice for a first programming language, so a large number of new programmers are never exposed to ‘bare bones’ development that some take for granted.

A programmer who doesn’t have to rely on an IDE to do his or her development is a more versatile, reliable and competent programmer.

Setting up a basic development environment without an IDE is not that difficult either. The most basic development environment really only needs three things:

Compiler: A compiler turns your source code (text) into executable object code (EXEs, DLLs, etc.). GCC is an example of a very popular and well-recognized compiler, but there are plenty of compilers out there for a variety of different target environments (think embedded processors).

Text Editor: Something to write the source code in. Notepad is the most basic example of a text editor, but there are much more advanced editors out there such as Notepad++.

Build System: In all but the simplest coding exercises, compiling is a tedious multi-step process. While not strictly necessary, a build system will automate many aspects of compilation. Make is a very popular build system for a variety of languages, while Java may use Ant or Maven.

If you just want to start learning C and compile C code on a desktop PC then you can’t go really wrong with the following combination:

Compiler: GCC

Build System: Make

Text Editor: See below

No one can really argue with the combination of GCC and Make - those two pieces software have been used together for 27 years. That’s an eternity in the computing field. If it was good enough for your parents it’s good enough for you isn’t it? Text editors are harder to recommend - there are quite a few of them to choose from and it’s largely a personal choice. But, since I have to give some sort of direction to initiates I’ll suggest that Windows users start out with Notepad++ and Linux/Unix users start out with nano. They’re both capable but simple to use.

Linux/Unix users have a much easier time setting up a C development environment. Chances are good that you already have all of the tools installed on your machine and if not, you have a package manager you can use to download them. Most likely you know how to do that anyway, so the rest of the article is dedicated to helping Windows users set up their development environments.

It’s rather easy to download and install NotePad++ so I’ll leave out those instructions. Getting ahold of Make and GCC on Windows is actually somewhat difficult. Those programs are part of a collection of software called the GNU toolchain and are native in Linux/Unix, on Windows there are several options for getting the GNU toolchain:

GNU Win32 - This is a collection of Linux/Unix command-line utilities designed to run on Windows

MinGW - This is a collection of Linux/Unix command-line utilities designed to run on Windows

Cygwin - This is a set of programs designed to provide a Linux/Unix environment on Windows

Of the three, Cygwin is the most capable option, but also the most complicated to set up. GNU Win32 and MinGW largely accomplish the same thing with MinGW having a slight advantage in simplicity of installation. For that reason, I selected the MinGW distribution of the GNU toolchain. The remainder of this article details how to install MinGW on Windows.

Setting Up A Development Environment

The first step is to download the MinGW installer. The simplest way is to go to http://mingw.org and click on the 'Download Installer' button in the upper right hand corner:









This will download mingw-get-setup.exe. Double click it to start the installation - the first screen will look like this:

Click ‘Install’. You'll be presented with some options:

The defaults are fine here, click ‘Continue’.

Now it downloads and installs for a while - when done ‘Continue’ will become enabled - click it.





And the Installation Manager will pop up offering several options for packages.

The controls are a bit odd - when you click on the boxes it brings up a menu to ask if you want to check the box. Two clicks where one would have sufficed, but I digress.

I selected the following packages as a start:

mingw-developer-toolkit

mingw32-base

msys-base

You can select more if you like by clicking on ‘All Packages’ on the left-hand side and you’ll have a lot more selections. The options I specified should get you started with a basic environment for compiling software. You can re-run the installer later to add more programs to your installation should the need arise.

When you’re done, go to the ‘Installation’ menu up top and click on ‘Apply Changes’.

This fancy window will come up to detail all of the changes that will be made:

Just click ‘Apply’ and it will start downloading and install.

Then it changes….

Until it’s done - then you can click ‘Close’.

See the green, filled boxes below? Those are installed now.

You can click on the ‘Installation’ menu and select ‘Quit’

There’s just one more thing you need to do to complete the installation: add the MinGW binaries directory to your PATH. You can do that this way:

Right-click ‘My Computer’, go to ‘Properties’

Find ‘System Properties’ or ‘Advanced System Settings’ and click it

There should be an ‘Environment Variables’ button - click it.

This window opens:

Click on the ‘New’ button on top and populate the window as seen below:

Click ‘OK’ and exit out of the rest of the windows by clicking ‘OK’ wherever necessary.

Now open up a command prompt and type ‘gcc’. You should see this:

This is sign that GCC (our C compiler) installed correctly and the path is correct. you can do the same for mingw32-make and you should see this:

Success! This means we can compile C programs and create makefiles to automate the build process.

Hungry for more? The next article in this series will address creating and compiling simple C programs and automating the build process with makefiles. Along a similar vein, programmers just starting out should also review my article on directory structure for advice on organizing projects written in C.