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

This page adds two tools to Textpad so that we can use the gcc compiler to do "separate compilations" of individual compilation units. The first tool will run the gcc compiler and tell it to only produce an object file and not to link that object file with anything. The second tool will run gcc and tell it to link an object file to other object files (that we will specify at a prompt that pops up) thereby producing an executable exe file.

These two tools are usefull for very small programs made up of at most three or four C/C++ source files (and any number of header files). If you have a project that is made up of more than four compilation units, or your compilation units need to be linked with several external libraries, then it is time to start using Make.

These steps assume that you have installed Texpad and gcc according to these instructions.

Step 1:
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 2:
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 boxes labeled "Prompt for parameters" and "Capture output" are checked and that the check box labelled "Save all documents first" is un-checked (the "Prompt for parameters" option is what will let us tell the linker about all the items that we want to link). 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.)


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


compliments and criticisms