Using the GNU C Compiler

 < Day Day Up > 

If you elected to install the development tools package when you installed Fedora Core (or perhaps later on, using RPM, or other package tools), you should have the GNU C compiler (gcc). Many different options are available for the GNU C compiler, and many of them are similar to those of the C and C++ compilers that are available on other Unix systems. Table 32.1 shows the important switches for gcc. You can look at the man page or information file for gcc for a full list of options and descriptions

Table 32.1. GNU C Compiler Switches

Switch

Description

-x language

Specifies the language; C, C++, Java, and assembler are valid values.

-c

Compiles and assembles only; does not link.

-S

Compiles; does not assemble or link. Generates an assembly code (.s) file.

-E

Preprocesses only; does not compile, assemble, or link.

-o file

Specifies the output filename. a.out is the default.

-l library

Specifies the libraries to use.

-I directory

Searches the specified directory for include files.

-w

Inhibits warning messages.

-pedantic

Requires strict ANSI compliance.

-Wall

Prints additional warning messages.

-g

Produces debugging information for use with gdb.

-ggdb

Generates native-format debugging info and gdb extensions.

-p

Produces information required by gprof.

-pg

Produces information for use by gprof.

-O

Optimizes the compilation.


NOTE

Fedora Core always includes a recent release of gcc, but newer versions of gcc appear from time to time. You should be aware that if you use gcc to develop programs for earlier versions of Linux, your programs might not load or run because of software library incompatibilities. You can always install an older version of gcc and compatible development libraries to support building programs that work with older versions of Linux. These problems can occur because older and newer versions of software libraries might have different ideas about how standard routines are used.


When you build a C program using gcc, the compilation process takes place in several steps:

1.

First, the C preprocessor parses the file. To do so, it sequentially reads the lines, includes header files, and performs macro replacement.

2.

The compiler parses the modified code to determine whether the correct syntax is used. In the process, it builds a symbol table and creates an intermediate object format. Most symbols have specific memory addresses assigned, although symbols defined in other modules, such as external variables, do not.

3.

The last compilation stage, linking, ties together different files and libraries and then links the files by resolving the symbols that had not previously been resolved.

NOTE

Most C programs compile with a C++ compiler if you follow strict ANSI rules. For example, you can compile the standard hello.c program (everyone's first program) with the GNU C++ compiler. Typically, you name the file something like hello.cc, hello.C, hello.c++, or hello.cxx. The GNU C++ compiler accepts any of these names.


     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net