Using the GNU Compiler Collection
- Using the GNU Compiler Collection
- Tutorial Example
- Common Command-Line Options
- Optimization Options
- Debugging Options
- Architecture-Specific Options
- GNU C Extensions
- PGCC: The Pentium Compiler
In This Chapter
Features of GNU CC
Common Command-Line Options
GNU C Extensions
PGCC: The Pentium Compiler
GNU CC, more commonly known as GCC, is the GNU project's compiler suite. It compiles programs written in C, C++, and Objective C. GCC speaks the various C dialects, such as ANSI C and traditional (Kernighan and Ritchie) C, fluently. It also compiles Fortran (under the auspices of g77). Front-ends for Pascal, Modula-3, Ada 9X, and other languages are in various stages of development. Because GCC is the cornerstone of almost all Linux development, I will discuss it in some depth. The examples in this chapter and throughout the book, unless noted otherwise, are based on GCC version 2.91.66.
Note - If you kick around the Linux development community long enough, you will eventually hear or read about another compiler, egcs, the Experimental (or Enhanced) GNU Compiler Suite. egcs was intended to be a more actively developed and more efficient compiler than GCC. It was based on the GCC code base and closely tracked GCC releases. To make a long story short, in April, 1999, the Free Software Foundation, maintainers of GCC, appointed the egcs steering committee as GCC's official maintainers. At the same time, GCC was renamed from the GNU C Compiler to the GNU Compiler Collection. In addition, the egcs and GCC code bases merged, ending a long fork in GCC's code base and incorporating many bug fixes and enhancements. So, egcs and GCC are, for all intents and purposes, the same program.
Features of GNU CC
GCC gives the programmer extensive control over the compilation process. The compilation process includes up to four stages:
You can stop the process after any of these stages to examine or use the compiler's output. You can control the amount and type of debugging information, if any, to embed in the resulting binary and, like most compilers, GCC can also perform code optimization. GCC allows you to mix debugging information and optimization. I strongly discourage doing so, however, because optimized code is hard to debug: static variables may vanish or loops may be unrolled, so that the optimized program does not correspond line-for-line with the original source code.
GCC includes over 30 individual warnings and three general warning levels. GCC is also a cross-compiler, so you can develop code on one processor architecture that will be run on another. Finally, GCC sports a long list of extensions to C and C++. Most of these extensions enhance performance, assist the compiler's efforts at code optimization, and make your job as a programmer easier. The price is portability, however. You will look at a few of the most common extensions because you will encounter them in the kernel header files, but I suggest you avoid them in your own code.