Installing c++/g++ on Windows

Disclaimer: This page is being maintained mainly for my students. Use these instructions at your own risk. There is no warranty in any form or shape whatsoever!. There is no guarantee that these instructions are up-to-date. With that understood you may continue with the rest of this page if you choose to accept these terms.

This page was last updated on September 13, 2005, but still good as of October 6, 2020.

Follow these steps to install g++ (the GNU C++ compiler) for Windows. There is no room for creativity here; you must follow the directions exactly.

  1. Pick the drive and a folder in which you want to install g++. I'll assume that it is C:, but you can choose a different one. If you choose a different drive or a different folder, you'll need to adapt the directions below accordingly.

  2. Download full.exe, an about 14 megabyte executable, to C:\full.exe by right-clicking on the link. Use Save Link As... or Save Target As... Be sure the browser saves the file as C:\full.exe.

  3. Run the downloaded executable. This will install g++ (and a lot of other things that you don't really need) on your hard drive. Go to the C: drive using Windows Explorer and double-click on full.exe. Or, open a DOS command prompt window (Start > Programs > Command Prompt), connect to the C: drive using the cd command, and type full.

  4. Locate where the bin folder was created for the g++ installation. On my Windows machine, it was created in the following path:
    C:\cygnus\cygwin-b20\H-i586-cygwin32\bin
    
    You now should add it to the PATH environment variable. You do that by following:
       ... -> Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables
    
    At this point you can see the PATH variable either in the User Variables or in the System Variables. Add the g++ path into either of the the PATH variables. If you are the only user of your computer, it does not matter which one you use. You add it to the end of the existing values either separated by a semicolon (';') if you are using an old machine or as a new line if you are using a new machine that has in that format. Make sure that you do not lose the original value. You are just appending more to the end either as a part of an existing line or a new line.

  5. Restart your computer. A Cygnus Solutions entry will appear in your Programs menu, and an icon may appear on your desktop. Don't use them! You will use it using the g++ command on a DOS command prompt as explained below.

You should now be able to run g++ from a DOS command prompt window. For example, to compile a file called C:\mine\hello.cpp, connect to the C:\mine folder and enter

       g++ -g hello.cpp -o hello -lm
You'll then be able to run the compiled program by entering hello in the DOS command prompt window.

If you've installed Emacs as described here, you will also be able to run g++ from Emacs. If you want to learn how to run g++ in emacs, see here.

If you'd like to learn more about where this free compiler came from, we downloaded it from an older site of http://sourceware.org/cygwin/.

If you wish to clean up a little, you may delete the file: full.exe at this point. Your g++ compiler is installed under C:\cygnus.


Maintained by Art Lee (alee at cmc dot edu).
Last modified . . .