Linking a program91
-fverbose-asm
-fpack-struct
-fstack-check
-fstack-limit-register=reg
-fstack-limit-symbol=sym
-fargument-alias
-fargument-noalias
-fargument-noalias-global
-fleading-underscore
3.4Linking a program
As mentioned earlier, building an executable binary file from a source code file is a multi-stage
process.
The
gcc
compiler usually carries all these steps for you by default. However you can stop
gcc
at any of these stages for various reasons. You have already seen how to create assembler
code from a C source code file. In most software projects, output binaries are built from many
source code files. For this purpose you have to compile these source code files to object files one
by one before you can generate the output binary file. After creating these object files, you can
link these files using
gcc
to the final executable.
The
gcc
compiler gets help from different programs during the four steps listed earlier in
this chapter. During the linking part, the
ld
program is invoked with appropriate arguments to
link one or many object files together with libraries to generate an executable. Command line
switches used with
ld
can be found using manual pages.
The linker is a part of GNU binary utilities package also known as binutils. You can down-
load and install the latest version of GNU linker if you need to do so.
3.5Assembling a Program
GNU assembler is part of GNU binary utilities package. To get the latest binutils packages, you
can download it from ftp://ftp.gnu.org/gnu/binutils/. After downloading you have to use the
tar
command to extract source code files. The latest version at the time of writing this chapter is
2.12 and the
tar
command will create a directory
binutils-2.12
automatically. I have
extracted it in
/opt
directory, so the source code directory is
/opt/binutils-2.12
. I cre-
ated another directory
/opt/binutils-build
to build the package. Running the
config-
ure
script is the first step towards building binary utilities package. The following sequence of
commands does all of these steps.
[root@conformix /opt]# cd /opt
[root@conformix /opt]# tar zxvf binutils-2.12.tar.gz
[root@conformix /opt]# mkdir binutils-build
[root@conformix /opt]# cd binutils-build/
[root@conformix binutils-build]# ../binutils-2.12/configure --
prefix=/opt/gcc-3.0.4 --enable-shared
Next Page >>
<< Previous Page
Back to the Table of Contents