Installing the MinGW (gcc) C++ compiler on your home computer

This page tells you how to download, install, and use the freely available C/C++ compiler MinGW. MinGW is a port of the gcc compiler to Microsoft Windows (gcc is the compiler for the Linux operating system). Below are several steps that lead you through the installation. The steps show you how to access the gcc compiler from the text editor TextPad.

Step 1:
First you need to download an installer file. Put this file in some temporary location on your computer.
MinGW compiler system installer (15 MB)
Note: This is not the most recent version of MinGW, but it is the easiest version to install.

Step 2:
Now run the installer. Have the installer install your copy of MinGW in the directory C:\MinGW. Do not install MinGW in the C:\Program Files directory. The space in that directory name can cause all kinds of problems.

Step 3:
If you have already installed TextPad on your computer (for use with another programming language), then skip to Step 5. Otherwise, download the TextPad text editor (the current version, at the time of this writing, is TextPad Version 5.1.0). TextPad is shareware; you can download and use it for free for a trial period, but then you are supposed to pay a shareware fee if you plan to continue using it. Use the following link to download the installation file (which is just over 2.7 MB in size).
ftp://download.textpad.com/pub/textpad5.1/txpeng510.exe

Step 4:
Install TextPad by double clicking on the installer that you just downloaded.

Step 5:
Run TextPad by finding it in your Start Menu. Click on the Tools menu at the top of the TextPad window. Several "tools" are pre-installed by TextPad. We need to install several new tools that let us use MinGW (i.e. gcc) from within TextPad.

Step 6:
We need to create a tool in TextPad to call the gcc compiler (without calling the linker). Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\MinGW\bin and then in that directory double click on the program g++.exe (make sure you choose g++.exe and not gcc.exe). Now you should be back to TextPad's "Preferences" window. Click on the name of the tool that you just created (its name should be at the bottom of the list of tools). Change the name of the tool to "G++ compile only". Click on the button "Apply" at the bottom of the "Preferences" window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "G++ compile only". Click on this item. This brings up a window where we can configure this tool. In the text box labeled "Parameters:" enter the following text (the -c option tells gcc to compile only, with no linking). (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
-Wall -g -c -o $BaseName.obj $File
In the text box labeled "Initial folder:" enter the following text:
$FileDir
In the text box labeled "Regular expression to match output:" (below all of the check boxes) enter the following text in place of what is currently there:
^\(..[^:]+\):\([0-9]+\):
Make sure that the check boxes labeled "Save all documents first" and "Capture output" are checked. Now click on the button "OK" at the bottom of the window. This completes the creation of the compiler tool. (You can check at this point and look in TextPad's "Tools" menu to see if the tool "G++ compile only" is at the bottom of the menu list.)

Step 7:
We need to create a tool in TextPad to call the gcc linker. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\MinGW\bin and then in that directory double click on the program g++.exe (make sure you choose g++.exe and not gcc.exe). Now you should be back to TextPad's "Preferences" window. Click on the name of the tool that you just created (its name should be at the bottom of the list of tools). Change the name of the tool to "G++ link only". Click on the button "Apply" at the bottom of the "Preferences" window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "G++ link only". Click on this item. This brings up a window where we can configure this tool. In the text box labeled "Parameters:" enter the following text. (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
-Wall -g -o $BaseName.exe $BaseName.obj
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check box labeled "Capture output" is checked and that the check box labelled "Save all documents first" is un-checked. (If you want to, you can check the box labelled "Prompt for parameters". If you do, each time you use this tool TextPad will prompt you for linker parameters; this makes it easy to link several seperate compilation units.) Now click on the button "OK" at the bottom of the window. This completes the creation of the linker tool. (You can check at this point and look in TextPad's "Tools" menu to see if the tool "G++ link only" is at the bottom of the menu list.)

Step 8:
We should create a tool in TextPad to call the gcc compiler and linker together. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\MinGW\bin and then in that directory double click on the program g++.exe (make sure you choose g++.exe and not gcc.exe). Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "G++". Click on the item "G++". This brings up a window where we can configure the "G++" tool. In the text box labeled "Parameters:" enter the following text. (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
-Wall -g -o $BaseName.exe $File
In the text box labeled "Initial folder:" enter the following text:
$FileDir
In the text box labeled "Regular expression to match output:" (below all of the check boxes) enter the following text in place of what is currently there:
^\(..[^:]+\):\([0-9]+\):
Make sure that the check boxes labeled "Save all documents first" and "Capture output" are checked. Now click on the button "OK" at the bottom of the window. This completes the creation of the compile and link tool. (You can check at this point and look in TextPad's "Tools" menu to see if the tool "G++" is at the bottom of the menu list.)

Step 9:
We need to create a tool in TextPad that lets us run a program that we have compiled and linked. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\Windows\system32 (on a Windows XP computer). Double click on the program cmd.exe. Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have either the item "cmd". Click on the appropriate item. This brings up the window where we can configure the tool. In the text box labeled "Parameters:" enter the following text:
/k $BaseName.exe
In the text box labeled "Initial folder:" enter the text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. This tool will run your C++ program one time and then leave you at a command prompt so that you can type other commands (you can use the "exit" command to close the console window).

Note: If your C/C++ program does not prompt the user for any input, then you can configure TextPad to capture your program's output and display it in an editor window. Change the text in the text box labeled "parameters:" to

/c $BaseName.exe
(notice that we are changing the switch /k to /c) and then check the check box labeled "Capture output". This technique can be useful for a variety of reasons, for example, you want to save the program's output, or you want an easier way to read a large amount of output, etc.

Step 10:
Now it is time to test TextPad. Use your browser to download and save this very short C++ program, hello.cpp, to your computer. Use TextPad to open hello.cpp. (You can use the "File -> Open" menu item in TextPad; you will need to remember where you had your browser store the hello.cpp file. Or, you can right click on the file hello.cpp and choose TextPad from the pop-up context menu.) Use the "Tools -> G++" menu item to have TextPad run the C++ compiler and linker. When the compiler tool finishes, use the "Tools -> Cmd" menu item to have TextPad open a command window (also called a "console window" or a "DOS box") and run the program hello.exe. After you see the program's output, close the command window and go back to TextPad. Purposely create an error in the program (delete a semicolon or misspell a name). Try to compile the program. When you get an error message from the compiler, double click on the line number in the error message. TextPad should jump to the line in the C++ program that the error message referred to.

Step 11:
In this step we will install a very simple IDE (integrated development environment), called Quincy 2002, that includes a simple debugger. Download the following zip file.
ftp://ftp.alstevens.com/quincy2002/quincy2002exe.zip
Unzip the contents of quincy2002exe.zip to the folder C:\quincy2002. The folder C:\quincy2002 now has a sub folder C:\quincy2002\bin. In the folder C:\quincy2002\bin is the program C:\quincy2002\bin\quincy.exe. Run the program C:\quincy2002\bin\quincy.exe by double clicking on it's icon. When Quincy 2002 is running, click on it's "Tools -> Options..." menu item. On the "Build" tab, there is a text box that has "Compiler:" written on its left hand side. In the text box enter the following text:
C:\MinGW\
Click on the "OK" button, which returns you to the main window of Quincy 2002. Use the "File -> Exit" menu item to quit Quincy 2002. Now start TextPad and create a tool that will start up Quincy 2002 for us. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\quincy2002\bin and then in that directory double click on the program quincy.exe. Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Quincy". The "Quincy" tool shouldn't need to be configured, so click on the button "OK", which should return you to the main TextPad window. Use TextPad to once again open the file hello.cpp. Compile hello.cpp. After it has been compiled, use the "Tools -> Quincy" menu item to start up Quincy 2002 with the file hello.cpp. In the tool bar near the top of the Quincy 2002 window there is an icon of a boot (next to an icon of someone running). Click on the boot icon. This starts the program running. Each time you click on the boot icon, one line of the program is executed (notice the little green arrow in the left margin next to the C++ code). This is called "single stepping" through the program. When you are done stepping through the program, exit Quincy 2002 and go back to TextPad. In class we will go over more about using the debugger in Quincy 2002 (e.g., setting breakpoints, setting watch variables, and using step over and step out).

Step 11.5 (optional):
There is some documentation on how to use Quincy 2002. Download the following zip file.
ftp://ftp.alstevens.com/quincy2002/quincy2002doc.zip
Unzip the file quincy2002doc.zip anywhere that is convenient for you. In the folder that you unzipped quincy2002doc.zip into there will be a file quincy2002.htm. Open this file with any web browser to read the Quincy 2002 documentation (usually you can just double click on the file quincy2002.htm to have it opened by your web browser). In particular, look at Section 7, Debugging a Program.

TextPad is a very powerful text editor. It has a lot of tools that make working with C, C++, Java, HTML, etc., files very easy. Editors like Notepad really pale in comparison to an editor like TextPad.

When you are editing your C/C++ source files, remember to save your work frequently (at least every 15 minutes), otherwise it may be Abort, Retry, Ignore?


Return to the main C++ Programming page.
Return to the CS 316 home page.


compliments and criticisms