Chapter 2. Basic Principles of the Tools
GNU preprocessor that processes all the header files and macros that your target requires (refer
•
cpp
to Section 2.5
cpp
GNU assembler that produces binary code from assembly language code and puts it in an object
•
as
file (refer to Section 2.6
GNU linker that binds the code to addresses, links the startup file and libraries to an object file,
•
ld
and then produces an executable binary image (refer to Section 2.7 ld, the GNU Linker).
To invoke the compiler, type:
gcc option, option...
Each
signifies input that allows you to control how the program compiles (for example, you
option
can interrupt a compile process at intermediate stages). Use commas to separate options. There are
many options available that provide specific types of compiled output, some for preprocessing, others
controlling assembly, linking, optimization, debugging, and still others for target-specific functions.
For instance, call the compiler with a
compilation pass.
implicitly recognizes the following file extensions:
gcc
(for C source code that must be preprocessed)
•
.c
(for C++ source code that must be preprocessed)
•
.C
(for assembler code)
•
.s
(for assembler code that must be preprocessed).
•
.S
When referring to C++ compilation,
is also accurate to use the
useful when the emphasis is on compiling C++ programs, with the GNU compiler acting not merely
as a preprocessor, but building object code directly from your C++ program source.
There is no intermediate C version of the program; avoiding an intermediate C representation of the
program means that you get better object code and better debugging information. The GNU debugger
works with this information in the object code to give you comprehensive C++ source-level editing
capabilities.
When you compile C or C++ programs, the compiler inserts a call at the beginning of
support subroutine. To avoid linking to the standard libraries, specify the
_main
(Including
at the end of your compiler command line resolves this reference and links only
-lgcc
with the compiler support library
get a chance to link first with any of your own special libraries).
is the initialization routine for C++ constructors. Because GNU C is meant to interoperate
_ _main
with GNU C++, even C programs must have this call; otherwise, C++ object files linked with a C
might fail.
main
Compilation can involve up to four stages, always in the following order:
preprocessing
•
compiling
•
assembling
•
linking
•
The first three stages apply to an individual source file: preprocessing establishes the type of source
code to process, compiling produces an object file, assembling establishes the syntax that the com-
piler expects for symbols, constants, expressions and the general directives. The last stage, linking,
completes the compilation process, combining all object files (newly compiled, and those specified as
input) into an executable file.
, the GNU Preprocessor).
, the GNU Assembler).
as
option to refer to precisely which options are in use for each
-v
is its customary name. Because there is only one compiler, it
g++
call, no matter what the language context. The
gcc
libgcc.a
; ending your command's input with it ensures that you
distinction is more
g++
to a
main
option.
-nostdlib
5
_
Need help?
Do you have a question about the ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE and is the answer not in the manual?
Questions and answers