gcc and makefiles
What is gcc?
"GCC is a free compiler collection for C, C++, Objective C and
There is extensive documentation at
Most common uses for gcc
Enable additional warnings in compiler output.
Include debugging information in output files (makes
files quite a bit larger).
Specifies a library to include in the linking stage. This
is necessary, for instance, when writing X programs.
-Idir, -Ldir -
Specifies directories to be searched for 1) #include files
and 2) libraries (specified with the -l option.
#define symbol 1 at the beginning of all
Using gcc to compile C++ programs
Use g++ instead of gcc.
Although gcc will recognize C++ source files by their extension,
the second step of the two-step method has no way of knowing
to use the C++ libraries instead of the C libraries.
Using g++ will tell the linker to use
the C++ libraries.
What is a makefile?
A makefile is a set of rules that tell how a program is compiled
and linked. They are useful for two reasons:
Simplifies building of large programs (Just type 'make').
If the program is built already, 'make' only compiles
the parts of the program that need to be compiled.
Writing a rule
A Makefile (usually named Makefile with a capital M so it
appears at the beginning of the directory listing) in its simplest
form is a list of rules that look like this...
target : prerequisites
The target and prerequisites refer to filenames in the local directory.
If any file in the prerequisites list was modified more recently than
the target file, the command following is executed. The command line
must begin with a tab character.
The order of rules in the Makefile does not matter, except the default
rule is the top one, so put the link command as the top rule
and all the compilation steps beneath it.
This is only a very basic introduction to Makefiles. More information
can be found on make's info page (type info make).
Last updated by
Jason Long on 2000 Feb 15.