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 https://cygwin.com/install.html.
- Choose your version of Cygwin, download the setup program and save it to a convenient place like the Desktop:
- setup-x86_64.exe: 64-bit computers
- setup-x86.exe: 32-bit computers
In the classroom we have installed 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:/cygwin64. 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. 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 in a format like the following image:
You will need to add the packages 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 with numbers that match those in the image above:
- 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 drop down box and select the highest numbered version that is not Test, or "Keep" if the highest numbered version is already installed.
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 Cygwin64 Terminal 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 terminal window as shown in the above image. The message, "no input files" will appear if the installation was 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.
- Click the Start menu
- In the text box, 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 64-bit Cygwin to 32-bit Cygwin.
- 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:\cygwin64\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 Cygwin64 Terminal 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. Verify you 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, verify you see a window like the following:
- To run the program type:
After running the command, verify you see a window displaying, "Hello, World!", like the following:
Last Updated: July 20 2021 @20:23:39