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
Note that in this case, the source file being compiled is always linked in first,
regardless of its position in the command line. This can be problematic
when a custom CRT is supplied as object file. As an alternative to
the above, foomain.c can be compiled separately, and the resulting
object file can then be linked with the other object files using a
separate command:
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 object files in the order they
are presented to it. The linker is invoked from SDCC using a script
file with extension .lnk. You can view this file
to troubleshoot linking problems such as those arising from missing
libraries.