|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.Disclaimer
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:
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 -vAssuming 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.Aside
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
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.cIf 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!".Aside
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.exeIn which case you will run the program by typing
instead.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.
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.