Quick Links

Download

Advertisements

Compiling C Code in Linux

The Compiler

If you are writing C programs in Linux (or want to) you will need a compiler. A compiler will read your .c files (C code written in any text editor, also referred to as source code) and generate an executable from it. All you need to do is find a compiler you like...


Nearly all Linux distributions come with some form of the GCC compiler; this is the compiler that appears to be the most widely used, and probably has the most information/tutorials available on the internet for free. GCC itself is free to use and can be downloaded from the internet. Some Linux distributions allow you to install GCC via the system's package manager. On Ubuntu, for example, you can use "apt-get" to install GCC by typing at the command line:

	   apt-get install gcc-x.x 

Substitute x.x for the version of GCC you want to install.

Source Code Management

In addition to the compiler, you will need some form of source code management tool. In my experience, the most widely used source-code manager is GNU Make. To use it, you write a "Makefile" that describes what source code files are to be used to compile the executable. Together, GNU Make and GCC will allow a programmer to generate executables to be run on Linux. As before, you can use your version of Linux's package manager to download GNU Make.


Relax...

If you download my tutorials, I will supply the Makefile and source code for you. Not everyone can, or chooses to, remember the specifics of how to write a Makefile. Many people have a standard template that they keep around and only modify the names of the input and output files for each project. So, do yourself a favor at this time and follow my examples; you need to be focusing on how to program well, not manage the code.


< Prev Tutorial Next Tutorial >



About the Author

Grant Dryden works as a computer engineer. He writes software in C and C++ for embedded systems as well as firmware in VHDL. He has a Bachelor of Science in Computer Engineering.