next up previous contents

[ENGN3213 Home]

   
Linking Two or More Object Files

It is often convenient to break up a software project into modules, develop each module, and link the modules together to give the final complete program.

Suppose we have three programs prog.c (top level), module1s.s, and module2c.c (2 C programs and 1 assembly program). You want to create an executable prog.x which includes all three components, and perhaps additional items from the C libraries. Procedure:

1.
Compile and assemble prog.c to get prog.o

2.
Assemble module1s.s to get module1s.o

3.
Compile and assemble module2c.c to get module2c.o

4.
Link them all togther with
m68k-coff-gcc -m5200 -Wl,-s -Wl,-n -Tsbc5206-srec.ld  
         prog.o module1s.o module2c.o  -o prog.x
(This should be on a single line.) This will give the executable prog.x which can be serially downloaded to the SBC.

Exercise - PREPARATION.

Write a program to count the number of characters in a string terminated by the letter E. To get practice with linking modules, break up your program into two modules. The first module sets up the string stored in memory and passes (by reference) the string to a subroutine contained in the second module. The second module returns the character count and the first module prints the value to the terminal screen.


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213