Compiling Howto

(How to compile programs with gcc)

© (2004) Pablo Arés, pablo /at/

Some comments on C files

Compiling C files is not difficult; the harder part is to write the files, and I can't write a C manual in this HOWTO. Please search the Internet, where there are lots of sites with help on C, or any book on C programming.

Compiling with gcc

First of all, the C compiler expect the name of the file to end in .c for a C file, and .cc for a C++ file (there are other endings, for assembly and include files, but I will not talk about those files here).

The compiling part is simple, just do

   gcc file.c
for a C file or
for a C++ file.

The output (executable) file will be called a.out If you want to get the output in a different file, do:

   gcc -o output-file file.c
There are many options you can give to the compiler. A common one is to get "all warnings" with
   gcc -Wall file.c
If you need to include some library, say the library with the crypt functions, called libcrypt.a, then do
   gcc -lcrypt file.c
Some times libraries are not found by the compiler, you will have to provide the directory where the library is. For example, the library libconv-core.a from the charm package is in /usr/local/char/lib. Then you can compile with
   gcc -L/usr/local/char/lib -lconv-core file.c
The -L option is to tell the compiler to search for libraries in that directory; the -l is, as above, to include the library in the compiling process.


To debug a C program you will have to compile it in a particular way:

   gcc -g file.c
The debugging utility in the GNU C compiler is called gdb You can run it on the executable file with:
   gdb a.out
for debugging in X-windows.

Parallel compiling

There are several utilities to do parallel compiling. Here is some more information:

Search the Internet for more documentation. If you find something useful, please send a mail to the webmaster so I can put it in our website.