Next Previous Contents

3. Compiling.

3.1 Single Source file projects.

For single source file projects the process is very simple. Compile your programs with the following command

sdcc sourcefile.c
 

The above command will compile ,assemble and link your source file. Output files are as follows.

3.2 Projects with multiple source files.

SDCC can compile only ONE file at a time. Let us for example assume that you have a project containing the following files.

foo1.c ( contains some functions )foo2.c (contains some more functions)foomain.c (contains more functions and the function main)
 

The first two files will need to be compiled separately with the commands

sdcc -c foo1.csdcc -c foo2.c
 

Then compile the source file containing main and link the other files together with the following command.

sdcc foomain.c foo1.rel foo2.rel
 

Alternatively foomain.c can be separately compiled as well

sdcc -c foomain.c sdcc foomain.rel foo1.rel foo2.rel
 

The file containing the main function MUST be the FIRST file specified in the command line , since the linkage editor processes file in the order they are presented to it.

3.3 Projects with additional libraries.

Some reusable routines may be compiled into a library, see the documentation for the assembler and linkage editor in the directory SDCCDIR/asxxxx/asxhtm.htm this describes how to create a .lib library file, the libraries created in this manner may be included using the command line, make sure you include the -L <library-path> option to tell the linker where to look for these files. Here is an example, assuming you have the source file 'foomain.c' and a library 'foolib.lib' in the directory 'mylib'.

sdcc foomain.c foolib.lib -L mylib
 

Note here that 'mylib' must be an absolute path name.

The view of the way the linkage editor processes the library files, it is recommended that you put each source routine in a separate file and combine them using the .lib file. For an example see the standard library file 'libsdcc.lib' in the directory SDCCDIR/sdcc51lib.


Next Previous Contents