UNIX VII: Compilers
- A compiler is a program which translates a program written
in a high level language into assembly or machine language.
- Most UNIX computers come with a C compiler called cc, but
unfortunately many of these compilers are nonstandard. In this class, we
will be using the GNU C compiler.
- [The GNU project was started by Richard Stallman to develop quality
free software for UNIX machines. GNU stands for GNU's Not Unix.]
- To access the GNU C compiler on Athena, first type add gnu.
Then to compile the source code in the file test.c, type
gcc test.c -g -ansi -o test.
- The -g option tells the compiler to include debugging
information in its output.
- The -ansi option tells gcc to compile your code
according to the ANSI specification of the C language.
- The -o test
tells gcc to put the executable output in a file named test.
- [For obscure historical reasons, if you don't add the -o test the
default behaviour is to put the executable in a file named a.out.]
- To run your program, just type test. To run your program
under gdb (the GNU debugger), type gdb test. Running
your program under a debugger allows you to step through it one
statement at a time and to examine the state of the computer's memory,
among other things.
Next Slide