On This Page
This document provides instructions for setting up a programming environment for use in CS-11. The environment is called Cygwin and is freely available from cygwin.com. Cygwin is already installed on CTC and lab machines. You can access the program in the labs from the Start button and by following the menu tree to CS & CIS courses.
If you need more help installing and using Cygwin, consult the Cygwin User's Guide. Or better yet, ask a class mate if they were able to set it up. If you are looking for instructions on setting up g++ for Mac OS X, see: How to Install g++ on the Mac
- Go to the site http://cygwin.com/install.html.
- Download the
setup-x86.exe program and save it to a convenient place like the Desktop.
Note for Windows 64 users: make sure you install the standard version (32 bit) and NOT the 64-bit version.
- Run the program and you will see a startup screen like the following. If you get a security warning then ignore it and run the program anyway. Click on the Next button to continue the installation.
- Choose A Download Source: Choose "Install from Internet" and click the Next button.
- Select Root Install Directory: Accept the defaults ("C:/cygwin", All Users, Unix) and click the Next button.
Important: The default root directory for Cygwin applications is
C:/cygwin. You may change it if you wish (using '/' rather than '\' as a directory separator), but do NOT choose a location that contains spaces anywhere in its path name.
- Select Local Package Directory: Accept the default or change it to any temporary directory of your choice. However, make a note of where you saved the files so you can delete the
.tar.xz files after the installation to save disk space. Click the Next button to continue.
- Select Your Internet Connection: Use the default setting unless you run into problems. Press the Next button to continue.
- Choose A Download Site: Any site that you can connect to is fine. Some sites are more stable or faster than others. Try to pick one that works for you. For a nearby site, look in the list of Mirror Sites and find a geographically close one. Press the Next button after selecting the download site.
- Select Packages (important!): The installer will show you a list of packages like those in the following image:
You will need to install all the programs listed below. Do NOT unselect any packages that are already selected by default and do NOT select all the packages and programs. Here is a suggested process:
- Change the View drop down box to "Category".
- Type or copy each package listed below into Search, such as "gcc-g++".
- Click the + sign to expand the category for Devel, Editors or Utils only.
- In the Package column, find the package name for the package that is an exact match. For example "gcc-g++".
Do not install packages that have only a partial name match.
- Verify the New column for the package row does NOT show "Skip". If it does show "Skip", click the New field for the row repeatedly until is shows the highest numbered version.
- If the Bin? column does not show
n/a, make sure it is checked as shown in the image above.
Repeat the above process for all the packages listed below.
- + Devel category
- + Editors category
- + Utils category
Once you have selected all the required programs listed above, click the Next button.
If the installation program asks to install other programs to resolve dependencies, accept the additions.
- Progress: This step will take some time that depends on the speed of your Internet connection and the speed of your computer. While the setup runs, you can view the progress of the installation.
Sometimes you may get a download incomplete and the setup application will return to step 8. Simply select another server and continue the installation process.
- Postinstall script errors: You may see a window like the following. If so, press Next to continue.
- Create Icons: You can install on the Desktop or the Start menu. Press the Finish button after you decide where you want them.
- As a final step, set windows to show filename extensions.
Though the installation is complete, you still need to go through the next section to be certain you installed Cygwin correctly.
Starting, Testing and Stopping Cygwin
Cygwin installs both icons on the Desktop and in the Start menu, if you accept the default settings. To start Cygwin, simply double-click the icon on the Desktop or select the Cygwin Bash Shell entry from the Start menu. You should see a window like the following. This is known as the terminal window, or sometimes the command window.
To verify that your installation was successful, type g++ in the window at the command line like shown in the above image. The message, "no input files" will appear if you were successful.
If you see the message, "no input files", then you installed Cygwin correctly. For example, you may see, "command not found". If so, you will need to uninstall Cygwin (by deleting the folder) and reinstall it. Please make sure you followed the Select Packages step exactly. If you still have difficulty after reinstalling, then please get help from a classmate or the instructor.
To stop Cygwin, type
exit in the console window.
For more information, see the Cygwin User"s Guide.
In Case of Trouble
- If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your
gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure in step 9 that you select the highest numbered versions of
After the update, verify you can compile and run.
- If you try to compile and see the message, "bash: g++: command not found", then you probably made a mistake selecting the packages on step 9. Go through the installation process again reading carefully. On step 9, make sure you are expanding the tree by clicking the [+] sign as shown in the image. Also make sure to select all the packages that are listed below the image.
- If you see a message such as, "bash is not a recognized command..." you should completely remove your Cygwin installation and reinstall. To remove your Cygwin installation, delete the install folder at
C:\cygwin and the download folder wherever you saved it. To help find the download directory, search your computer for any directory name containing "cygwin".
- If you try to start Cygwin and it appears only briefly and then disappears, try starting Cygwin from the command line.
- From the Start menu, Select
(In Windows 7 or later, use the search box.)
- In the text box, type:
- command for Windows 95/98/ME
- cmd for Windows NT/2000/XP/Windows 7/8
- At the command prompt type:
Cygwin will report any errors it has while starting.
- If you see the following error:
Error: could not fork child process: Resource temporarily unavailable.
DLL rebasing may be required. See 'rebaseall / rebase --help'.
First try restarting your computer. If that does not help the try reinstalling by rerunning the Cygwin
setup.exe program without installing/updating.
If the above does not work, then check if you have incompatible software installed on your computer. Sometimes these problems can be worked around, by temporarily or partially disabling the offending software.
If the above does not work then switch from 32-bit Cygwin to 64-bit Cygwin, if your OS and CPU support that.
- If you have other problems installing or using Cygwin, try looking through the Cygwin FAQ. If this does not help, then email the instructor with a description of the problem or ask a classmate to help you. Make sure you include any error messages with your description of the problem. Screen shots are also helpful.
Compiling and Running Programs
In this section we look at how to compile and run C++ programs using your Cygwin installation.
- Copy the following program into a text editor like TextPad or Notepad.
using namespace std;
cout << "Hello, World!\n";
} // end of main function
Note that MS Word, or any other word-processing program, is NOT a good choice for a text editor. You can make them work but they are too cumbersome and error prone for working with source code.
- Save the program file as
hello.cpp in your Cygwin home directory using the name:
The Cygwin home directory is
C:\cygwin\home\username, where username is your login name on your computer. Make certain that you save the program with the correct file extension of
cpp. Windows will automatically add the wrong file extension, unless your text editor is showing the Save as type: "All files (*.*)" in the box under the file name.
- Start Cygwin by double-clicking the icon on the Desktop or selecting the Cygwin Bash Shell entry from the Start menu.
In the terminal window, you can use commands like
cd to change directories,
ls (el-es, not one-es) to list files and
pwd to print the working directory.
- In the command window, use the
ls (el-es, not one-es) command to list all your files. You should see
hello.cpp in the terminal window like the following.
If you do not see the file listed, then you did not save the file in the same folder that Cygwin is viewing. Type
pwd and press the Enter key to show the current folder and then resave the file into the correct folder.
- Compile the hello.cpp program by typing the following command at the command prompt and then pressing the Enter key:
g++ -Wall -Wextra -Wpedantic -o hello hello.cpp
After running the command, you should see a window like the following:
- To run the program you type:
After running the command, you should see a window displaying, "Hello, World!", like the following:
Last Updated: February 14 2018 @16:12:01