uwlogo CS137 - Programming Principles

Setting up GCC on Windows

For the CS 137 course, you may use whatever tools you have to compile your program. The purpose of this page is to help you set up the GCC compiler on your Windows machine.


This is not the only nor the official way to compile your C programming assignments.

In fact, we recommend that students either come to the computer labs on campus, or log in remotely in order to get the exposure to the Unix environment. Also, since all computers are different, we cannot guarantee that these instructions will work as intended on your machine. But if you are just getting started with C programming, there is a good chance that this page can give you a quick start.

Installing GCC

Installing GCC is easy. Here's what you do:

  1. Download the GCC installer here.
  2. Run the installer.
  3. Click next, next, "I agree", next, next, next, install.
  4. The installation will take a few minutes. Click next, finish when it's done.

That's it. GCC is now installed on your computer.

So, I can compile C programs now?

You bet. You can now compile programs on your command prompt.

Click on your Start menu, go into Accessories, and then click Command Prompt. Within the command prompt, type the following and then press enter:

c:\mingw\bin\gcc -v
Assuming that you installed GCC in the default directory, the command just now should spew out a long, cryptic message that ends with the line
gcc version 3.4.5

If you see that, then GCC has been installed properly.


By default, the Windows command prompt does not know where GCC is installed. This is why you need to type the full directory (c:\mingw\bin\) before the gcc command. In the Mac lab terminals, simply typing

gcc -v

should give you the version information.

Compiling Assignment 0

For this section, I'm assuming that you've already have the hello.c file written up and saved somewhere in your C drive. If you don't have it, now is the time to write it. Open up command prompt. Type

cd c:\<your directory>
Replace "<your directory>" with the directory in which you saved hello.c. Then, type
c:\mingw\bin\gcc hello.c
If your GCC was installed properly (see previous section) and you don't have any typos in your hello.c program, there should now be an executable called a.exe in the same directory. You can now run it:

and it will output the text "Hello world!".


Alternatively, if you would like to name your executable something other than a.exe, you can do so by the following command

c:\mingw\bin\gcc hello.c -o filename.exe
In which case you will run the program by typing


Setting up environment variables

This section is optional. After programming for a while, if you are tired of writing the complete path c:\mingw\bin every time you compile a program, you may want to know that there is a workaround. You can actually tell your command prompt where your compiler is installed.

  1. Go to the control panel.
  2. Switch over to classic view and cilck 'System'.
  3. If you are using XP, cilck the 'Advanced' tab.
    If you are using Vista or 7, click 'Advanced system settings' on the sidebar.
  4. Click 'Environment Variables'
  5. Under the System variables, find the variable called 'Path'
  6. Click 'Edit'
  7. Add the following to the end of the Variable value textbox. Do not remove what's already there:
    If you installed GCC in another directory, replace c:\mingw\ with your directory, but keep the 'bin' part.
  8. Click OK, OK, OK
  9. Open a new command prompt window. If you already have a command prompt window opened, close and reopen.
  10. Try typing
    gcc -v
    If everything was done correctly, the command prompt should recognize the gcc command and tell you the version number. From now on, you only need to type "gcc" to compile your programs!

*sniffle* It's not working for me...

If these instructions are not working on your machine, feel free to contact the course ISA for help. You can find his/her contact information on the personnel page.