Next Previous Contents

4. The linker

The linker combines several object and library files into one output file. ld65 is very configurable, but fortunately has built-in configurations, so we don't need to mess with configuration files, here.

The compiler uses small functions to do things that cannot be done inline without a big impact on code size. Those runtime functions, together with the C library, are in an object-file archive named after the system, in this case, "c64.lib". We have to specify that file on the command line, so that the linker can resolve those functions.

Let's link our files to get the final executable:

        ld65 -t c64 -o hello hello.o text.o c64.lib

The argument after -o specifies the name of the output file, the argument after -t gives the target system. The following arguments are object files or libraries. Since the target library resolves imports in hello.o and text.o, it must be specified after those files.

After a successful linker run, we have a file named "hello", ready for our C64!

For more information about the linker, see ld65.html.


Next Previous Contents