Compiler


The compiler is a program that transforms the C source code into a program your computer can run. The installation process for these is different depending on what operating system you are running.

Compiling and running C programs is also going to require really basic usage of the command line. This I will not cover, so I am going to assume you have at least some familiarity with using the command line. If you are are worried about this then search for online tutorials on using it, relevant to your operating system.

On Linux you can install a compiler by downloading some packages. If you are running Ubuntu or Debian you can install everything you need with the following command sudo apt-get install build-essential. If you are running Fedora or a similar Linux variant you can use this command su -c "yum groupinstall development-tools".

On Mac you can install a compiler by downloading and installing the latest version of XCode from Apple. If you are unsure of how to do this you can search online for “installing xcode” and follow any advice shown. You will then need to install the Command Line Tools. On Mac OS X 10.9 this can be done by running the command xcode-select --install from the command line. On versions of Mac OS X prior to 10.9 this can be done by going to XCode Preferences, Downloads, and selecting Command Line Tools for Installation.

On Windows you can install a compiler by downloading and installing MinGW. If you use the installer at some point it may present you with a list of possible packages. Make sure you pick at least mingw32-base and msys-base. Once installed you need to add the compiler and other programs to your system PATH variable. To do this follow these instructions appending the value ;C:\MinGW\bin to the variable called PATH. You can create this variable if it doesn’t exist. You may need to restart cmd.exe for the changes to take effect. This will allow you to run a compiler from the command line cmd.exe. It will also install other programs which make cmd.exe act like a Unix command line.

Testing the Compiler

To test if your C compiler is installed correctly type the following into the command line.

  1. cc --version

If you get some information about the compiler version echoed back then it should be installed correctly. You are ready to go! If you get any sort of error message about an unrecognised or not found command, then it is not ready. You may need to restart the command line or your computer for changes to take effect.

Different compiler commands.

On some systems (such as Windows) the compiler command might have a different name such as gcc. Try this if the system cannot find the cc command.