Minimalistic GNU for Windows

These instructions will show you how to download and install the command-line version of MinGW. Most students in CS 150 and CS 250 will be better-served by downloading and installing DevC++, which includes MinGW, instead of following these instructions.

What is MinGW?

MinGW ("Minimalistic GNU for Windows") is a command-line C/C++ compiler and utilities, based on the GNU GCC project. It compiles and links code to be run on Win32 platforms (Win95 through XP). Unlike some other versions of GCC, MinGW uses the Microsoft runtime libraries, distributed with the Windows operating system. Since these runtime libraries are not distributed using GNU's General Public License (GPL), you do not have to distribute your source code with your programs unless, of course, you use a GPL library in your programs.

MinGW comes with everything you need to compile and link both console-mode and GUI programs that will run on Windows 95/98/NT/2K/XP; your programs will not run on Windows 3.1 or on plain DOS machines however.

MinGW does not come with an Integrated Development Environment [IDE]. Instead, you write your source code using a text editor, such as Windows Notepad or SciTE. You then compile, link, and run your programs from the command-line, (that is, an MS-DOS or Command Prompt window.)

The rest of this page will walk you through the steps necessary to download, install, and run your C++ programs using MinGW.

Step 1: Download MinGW

AVisit the main MinGW download site at:

http://www.mingw.org/download.shtml

Locate and click the File List link as shown here: MinGW download site

BIn the file list, locate and click the current version of MinGW. This will have an .exe extension as shown here:
MinGW download link

CThe actual files you download are hosted on mirror sites around the country. You'll be given a chance to select a mirror. I usually select the University of North Carolina, (Chapel Hill), but any of them should be all right.
Selecting a mirror site to download from

DWhen the download dialog (below) appears, click Save, rather than Open:
Saving the file

ESave the file in a download or temporary directory on your local machine. (Be sure to remember where you put it!). The downloaded file is about 14.5 MB.
Saving the file.

Step 2: Install MinGW

AUsing Windows Explorer, locate the file you downloaded, and double-click it:
Locate the file using Windows Explorer.

BClick Yes when the dialog asks you if you want to install MinGW, as shown here:
Setup "Do you want to Install" dialog.

CMinGW uses a regular "InstallShield" type installer. Click Next when the introductory screen, shown here, appears:
Introductory installer screen.

DRead through the license and then click Yes to install:
Reading and agreeing to the license.
MinGW is released under the GNU Public License, (GPL), which allows you to obtain and modify the source code to the compiler. If you do so, then the changes you make must also be released under the GPL. However, the programs you create with MinGW don't normally link with GPL libraries, so you are free to distribute the programs you write using MinGW in any way you wish.

ESelect a folder where you would like to install MinGW. It's best if you don't use a folder that contains spaces, (such as "Documents and Settings"). As you can see here, I've created a folder named bin, where I install all of the programs that I use. Click Next once you've selected a folder:
Selecting the installation folder.

FHere's the dialog that is displayed while the files are decompressed and installed :
Installing the runtime files.

GOnce the files are copied, click Finish to finalize the installation:
Finishing the installation.

Step 3: Configure the PATH

Before you can use the compiler and tools, there is one more step you have to complete: you have to modify the PATH environmental variables so that the Command Prompt knows how to find the compiler executable program. (I've never understood why the installation program doesn't do this automatically.) There are two ways to set the PATH variable, depending upon the version of Windows you are using.

AIf you are using Windows 9x, then you'll need to modify (or create) the C:\AUTOEXEC.BAT file. Open the file using Notepad, and add a line like this to the end of the file:

PATH=C:\bin\MinGW\bin;%PATH%
This line adds the C:\bin\MinGW\bin folder to the existing executable path, assuming that you installed MinGW into the folder C:\bin\MinGW. If not, replace C:\bin\MinGW with the name of the folder you selected in Step 2E. Make sure, however, that your addition ends with bin, which is the name of the folder where MinGW keeps its executable programs.

You'll have to reboot your computer after making changes to the AUTOEXEC.BAT file, and before those changes will take effect.

BWith Windows 2000 or Windows XP, you don't have to modify a file. Instead, simply right-click on the My Computer Icon, and select Properties:
Selecting the Properties.

CWhen the System Properties dialog appears, choose the Advanced tab, and then click the Enviromental Variables button at the bottom of the dialog, as shown here, for Windows XP:
Setting the Environmental Variables.

DWhen the Environmental Variables dialog appears, locate the Path variable in the Sytem variables list box, and click Edit as shown here:
Editing the Path variable.

EWhen the Edit System Variable dialog appears, add the following to the beginning of the value that already exists:

C:\bin\MinGW\bin;
This adds the C:\bin\MinGW\bin folder to the existing executable path, assuming that you installed MinGW into the folder C:\bin\MinGW. If not, replace C:\bin\MinGW with the name of the folder you selected in Step 2E. Make sure, however, that your addition ends with bin;, which is the name of the folder where MinGW keeps its executable programs.
Adding MinGW\bin to the Path.
Click OK, and close all of the open dialog windows.

Step 4: Test Your Installation

AOpen a Command Prompt window. In Windows 2000 and Windows XP, you'll find this on the Accessories menu like this:
Opening a Command Prompt Window.
With Windows 9X, the Command Prompt is called the MS-DOS Prompt and you'll find it on the Start menu.

BUse the CD command to change to the folder where you keep the files for your class. In the example shown here, I'm using a folder called C:\docs\CS250:
Changing to the CS250 folder.
If you haven't created a work folder yet, you can do it now using Windows Explorer. Your life will be a whole lot easier, if you avoid a folder name that contains spaces. (In other words, use C:\docs\CS250, rather than something like C:\Documents and Settings\Owner\My Documents\CS250.)

CMake sure everything is set up correctly by typing the following command and then pressing ENTER:

C:\docs\CS250> g++ --version
If everything is installed correctly, you'll see a version message that looks something like this:
Checking the version.
If, instead, you see something like this:
Path error.
it means you made a mistake in Step 3: Setting the PATH. Redo the Step 3, and then test it again with Step 4, until you see a version message, such as that shown here.

Step 5: Compile and Run I

Here are the instructions you'll need to compile and run your programs using the Command Prompt and Notepad. The example shown here will use one file (hello.cpp) that prints "Hello World".

ACreate a folder to hold your project, using the md command, and then change into the working directory, using the cd command. Finally, create your source code file by typing notepad hello.cpp as shown here:
Creating a folder for your project.
Click Yes when asked if you want to create the new file, as shown here:
Creating a source code file.

BType in the source code for your program, as shown here:
Typing in your source code.

CSave your source code, and then switch to the Command Prompt window to compile and run.

To compile, use the command:

C:\docs\CS250\hello> g++ hello.cpp -o hello.exe
The first argument (hello.cpp) is the name of your source file. The -o (dash-Oh) switch allows you to specify the name of the output file, in this case hello.exe. If you don't use the output file switch, the output file will be named a.exe, instead of hello.exe.

To run the program, use the command:

C:\docs\CS250\hello> hello
Here's what the compile and run commands look like:
Compile and run your program.

Step 6: Compile and Run II

Here are the instructions you'll need to compile and run your multi-file programs using the Command Prompt and Notepad. The example shown here will use three files:

  • hello.h that contains the interface for the class named Hello
  • hello.cpp that contains the implementation of the Hello class.
  • sayhi.cpp that creates two Hello objects and has them speak.

ACreate a folder to hold your project, using the md command, and then change into the working directory, using the cd command. Finally, create your source code files by typing notepad hello.cpp, notepad hello.cpp, and notepad sayhi.cpp as shown here:
Creating the sayhi project.
Answer Yes each time Notepad asks if you want to create the new file, just like you did in the previous example.

BType in the source code for all three files, as shown here:
Typing in your source code.

CSave your source code, and then switch to the Command Prompt window to compile and run.

To compile, use the command:

C:\docs\CS250\sayhi> g++ hello.cpp sayhi.cpp -o sayhi.exe
This time, both files (hello.cpp and sayhi.cpp) are listed on the command line. You don't list hello.h, however, since it is included by both cpp files.

To run the program, use the command:

C:\docs\CS250\sayhi> sayhi
Here's what the compile and run commands look like:
Compile and run your program.