![kueller](/assets/img/avatar_default.png)
git-svn-id: svn://svn.compuextreme.de/Viitor/V961/Viitor_cc65@4236 504e572c-2e33-0410-9681-be2bf7408885
56 lines
2.2 KiB
HTML
56 lines
2.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20">
|
|
<TITLE>cc65 Compiler Intro: The linker</TITLE>
|
|
<LINK HREF="intro-5.html" REL=next>
|
|
<LINK HREF="intro-3.html" REL=previous>
|
|
<LINK HREF="intro.html#toc4" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="intro-5.html">Next</A>
|
|
<A HREF="intro-3.html">Previous</A>
|
|
<A HREF="intro.html#toc4">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s4">4.</A> <A HREF="intro.html#toc4">The linker</A></H2>
|
|
|
|
|
|
<P>The linker combines several object and library files into one output file.
|
|
<B>ld65</B> is very configurable, but fortunately has a built-in configuration
|
|
for the C64, so we don't need to mess with configuration files, here.</P>
|
|
<P>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,
|
|
"<CODE>c64.lib</CODE>". We have to specify that file on the command line, so that the
|
|
linker can resolve those functions.</P>
|
|
<P>A second file (this time, an object file) needed is the startup code that
|
|
prepares the grounds for the C program to run. The startup file must be
|
|
executed first, so it must be the first file on the linker command line.</P>
|
|
<P>Let's link our files to get the final executable:</P>
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
ld65 -t c64 -o hello c64.o hello.o text.o c64.lib
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
</P>
|
|
<P>The argument after <CODE>-o</CODE> specifies the name of the output file, the argument
|
|
after <CODE>-t</CODE> gives the target system. As discussed, the startup file must be
|
|
the first input file on the command line (you may have to add a path here, if
|
|
<CODE>c64.o</CODE> is not in your current directory). Since the library resolves
|
|
imports in <CODE>hello.o</CODE> and <CODE>text.o</CODE>, it must be specified <EM>after</EM> those
|
|
files.</P>
|
|
<P>After a successful linker run, we have a file named "<CODE>hello</CODE>", ready for
|
|
our C64!</P>
|
|
<P>For more information about the linker, see
|
|
<A HREF="ld65.html">ld65.html</A>.</P>
|
|
|
|
|
|
|
|
<HR>
|
|
<A HREF="intro-5.html">Next</A>
|
|
<A HREF="intro-3.html">Previous</A>
|
|
<A HREF="intro.html#toc4">Contents</A>
|
|
</BODY>
|
|
</HTML>
|