Compiler 
Operation 
-
linking 
a  C 
Program 
•  Sets up the system stack. 
•  Processes  the runtime initialization table and  autoinitializes global vari-
ables  (in the 
ROM  model). 
•  Calls --main. 
e  Calls 
exit 
when 
main 
returns. 
Section 
6 describes additional runtime-support functions that 
are 
included in 
rts 
.lib. 
If 
your  program 
uses 
any 
of 
these  functions,  you  must  link 
rts 
.lib 
with 
your object files. 
3.5.2 
Sample 
linker 
Command 
File 
3-14 
Figure 
3-5 
shows a typical  linker command  file that 
can 
be  used 
to 
link a C 
program.  The command file in  this example 
is 
named 
link. 
cmd. 
/***************************************************/ 
/* 
Linker 
command 
file 
link.cmd 
*/ 
/***************************************************/ 
-c 
/* 
ROM 
autoinitialization 
model 
*/ 
-m 
example.map 
/* 
Create 
a  map 
file 
*/ 
-0 
example. 
out 
/* 
Output 
file 
name 
*/ 
main.obj 
/* 
First 
C 
module 
*/ 
sub.obj 
/* 
Second 
C 
module 
*/ 
asm.obj 
/* 
Assembly 
language 
module 
*/ 
-1 
rts.lib 
/* 
Runtime-support 
library 
*/ 
-1 
flib.lib 
/* 
Floating-Eoint 
library 
*/ 
-1 
matrix. 
lib 
/* 
Object 
Ii 
rary 
*/ 
Figure 
3-5. 
An 
Example 
of 
a 
Linker 
Command 
File 
•  The command file first lists several  linker options: 
-c 
is 
one 
of 
the options that can  be  used  to link  C code;  it tells the 
linker to 
use 
the ROM model 
of 
autoinitialization. 
-m 
tells the linker 
to 
create  a map file;  the map file in this example is 
named 
example. 
map. 
-0 
tells the linker to create 
an 
executable object module; the module 
in  this example is named 
example. 
out. 
•  Next, the command file lists all the object files to be linked.  This C pro-
qram  consists 
of 
two 
C  modules, 
main. 
c  and 
sub. 
c, 
which 
were 
ompiled and  assembled  to create 
two 
object files called 
main. 
obj 
and 
sub. 
obj. 
This  example  also  links  in 
an 
assembly  language  module 
called 
asm. 
obj. 
One 
of 
these files must define the symbol 
main, 
because 
boot. 
obj 
calls 
main 
as 
the start 
of 
your C program.  All 
of 
these object files are linked 
in. 
•  Finally, the command file lists all the object libraries that the linker must 
search.  (The libraries 
are 
specified 
with 
the -I linker option.)  Since this 
is 
a C program, the runtime-support library 
rts 
.lib 
must 
be 
included. 
If 
a program 
uses 
floating-point 
routines, 
it 
must also  link in 
flib 
.lib