![]() |
Computer Systems Lab CS1000 |
![]() Wiscinfo |
![]() CS Home |
![]() CSL |
![]() CS1000 |
![]() Feedback |
Since compilers are generally complex, and since there are several available, details of their operation will not be discussed here. Further information is available by using the man command, from your instructor, from a UNIX consultant, or from the DoIT Documentation desk. In general, all compilers take their input from a file specified on the command line. Unless otherwise indicated, all will produce an executable called a.out. Below is the general form of a compiler command. On the following page are some sample compiler invocations:
The C Compiler | ||
---|---|---|
vega1% gcc.prog1.c | compile the C program prog1.c into a.out | |
vega1% gcc prog1.c -o prog1 | compile prog1.c into prog1 | |
vega1% gcc part1.c part2.c -o bar | compile both part1.c and part2.c | |
vega1% gcc -g prog1.c | compile the C program prog1.c into a.out with the debugging flag turned on | |
The C++ Compiler | ||
vega1% g++ prog1.cc | compile the C++ program prog1.cc into a.out | |
vega1% g++ prog1.cc -o prog1 | compile prog1.cc into prog1 | |
vega1% g++ part1.cc part2.cc -o bar | compile both part1.cc and part2.cc into bar | |
vega1% g++ -g prog1.cc | compile the C++ program prog1.cc into a.out with the debugging flag turned on | |
The Pascal Compiler | ||
vega1% pc prog1.p | compile prog1.p into a.out | |
The Fortran Compiler | ||
vega1% f77 prog1.f | compile the Fortran program prog1.f into a.out | |
vega1% f77 prog1.f -o prog1 | same except produce prog1 instead of a.out | |
vega1% f77 prog1.f -lnag | compile your program with the NAG library | |
The Assembler | ||
vega1% asm prog1.s | assemble prog1.s to produce prog1.o | |
vega1% ldm prog1.o | link and load prog1.o to produce prog1 |
The optional -g option for the C and C++ compilers tells the compiler to add debugging information when it compiles the code. This can then be used with the debugger gdb. This is especially useful for tracking down unknown errors. If your program crashes and dumps core, you can find out what line of your code the program was at with the following:
vega1% gdb a.out core
See the man page on gdb for more information on how to use it.