next up previous contents index
Next: 3.2 Command Line Options Up: 3. Using SDCC Previous: 3. Using SDCC   Contents   Index

Subsections

3.1 Compiling

3.1.1 Single Source File Projects

For single source file 8051 projects the process is very simple. Compile your programs with the following command "sdcc sourcefile.c". This will compile, assemble and link your source file. Output files are as follows

sourcefile.asm - Assembler source file created by the compiler
sourcefile.lst - Assembler listing file created by the Assembler
sourcefile.rst - Assembler listing file updated with linkedit information, created by linkage editor
sourcefile.sym - symbol listing for the sourcefile, created by the assembler
sourcefile.rel - Object file created by the assembler, input to Linkage editor
sourcefile.map - The memory map for the load module, created by the Linker
sourcefile.ihx - The load module in Intel hex format (you can select the Motorola S19 format with -out-fmt-s19)
sourcefile.cdb - An optional file (with -debug) containing debug information

3.1.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.c
sdcc -c foo2.c

Then compile the source file containing the main() function and link the 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.1.3 Projects with Additional Libraries

Some reusable routines may be compiled into a library, see the documentation for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc) for how to create a .lib library file. Libraries created in this manner can be included in the command line. Make sure you include the -L <library-path> option to tell the linker where to look for these files if they are not in the current directory. Here is an example, assuming you have the source file foomain.c and a library foolib.lib in the directory mylib (if that is not the same as your current project):

sdcc foomain.c foolib.lib -L mylib

Note here that mylib must be an absolute path name.

The most efficient way to use libraries is to keep seperate modules in seperate source files. The lib file now should name all the modules.rel files. For an example see the standard library file libsdcc.lib in the directory <installdir>/share/lib/small.


next up previous contents index
Next: 3.2 Command Line Options Up: 3. Using SDCC Previous: 3. Using SDCC   Contents   Index
Johan Knol
2001-07-13