Compiling your programs in Unix

Compilers

The C compiler normally used is 'gcc' . (If you have problems compiling a program, 'cc' may give you different error messages.) The normal usage is 'gcc source_file_name' which causes your executable to be called 'a.out'. The output file can be specified by adding the option '-o file_name'. However the best way, especially when using multiple files, is to use makefiles, as discussed next.

Makefiles

A file with the name 'makefile' will automagically execute commands for you by typing 'make'. Here is an example makefile which is just for compiling one program with 7 source files. It can be copied to create a simple makefile. Not only does this save typing, but it means that only files which have been changed need to be recompiled, saving time.

A more flexible makefile could compile one of several programs by typing 'make program'. This is shown in this example makefile where the makefile can do several different things. Note how a makefile can include any command, not just compile.

You can download and modify either of these for your own programs and source code, and soon you will be compiling your own programs with ease.