If you want to do C++ programming at home, then you need to install a C++ programming environment on your computer. One option is for you to install Microsoft Visual Studio 6 or Microsoft Visual Studio .Net on your computer. You can purchase these programs at the campus bookstore for just $10.00 each. I highly recommend that you get one of these programs and install it on your computer. We will go over in class some of the basics of using them.
Another option for C++ programming at home is to download and install 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. This file is fairly large, so you may want to do this download on campus and then transfer the file to either a zip disk or a CD-R disk. Put the file in some temporary location on your computer.
MinGW compiler system installer (15 MB)
- 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 4.7.2). 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 1.9 MB in size).
ftp://download.textpad.com/pub/textpad4.7/txpeng472.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 two 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 and 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 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 compiler 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 7:
- 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 on a Windows 98 computer, or the directory C:\WINNT\system32 on a Windows 2000 computer, or the directory C:\Windows\system32 on a Windows XP computer. On a Windows 98 computer, double click on the program command.exe . On a Windows 2000 or 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 "command" or "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++ 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, or you are using Windows 98 and the console window does not have a line buffer, etc.
- Step 8:
- 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 9: (optional)
- At this point, the tools that we created have pretty unappealing names. You can use the "Configure -> Preferences..." menu item to edit these names by clicking on the word "Tools" in the left hand pane of the "Preferences" window and then clicking on a tool in the middle pane and editing the name of the tool.
- Step 10:
- 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 10.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.
- Step 11 (optional)
- On a separate page there are instructions for adding some advanced C/C++ tools to TextPad.
|
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?
|