gbdk-releases/sdcc/doc/sdccman.html/node20.html
2015-01-10 16:25:09 +01:00

233 lines
7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>3.1 Compiling</TITLE>
<META NAME="description" CONTENT="3.1 Compiling">
<META NAME="keywords" CONTENT="sdccman">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="sdccman.css">
<LINK REL="next" HREF="node21.html">
<LINK REL="previous" HREF="node19.html">
<LINK REL="up" HREF="node19.html">
<LINK REL="next" HREF="node21.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html540"
HREF="node21.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
<A NAME="tex2html534"
HREF="node19.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
<A NAME="tex2html528"
HREF="node19.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
<A NAME="tex2html536"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
<A NAME="tex2html538"
HREF="node61.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
<BR>
<B> Next:</B> <A NAME="tex2html541"
HREF="node21.html">3.2 Command Line Options</A>
<B> Up:</B> <A NAME="tex2html535"
HREF="node19.html">3. Using SDCC</A>
<B> Previous:</B> <A NAME="tex2html529"
HREF="node19.html">3. Using SDCC</A>
&nbsp <B> <A NAME="tex2html537"
HREF="node1.html">Contents</A></B>
&nbsp <B> <A NAME="tex2html539"
HREF="node61.html">Index</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html542"
HREF="node20.html#SECTION00041100000000000000">3.1.1 Single Source File Projects</A>
<LI><A NAME="tex2html543"
HREF="node20.html#SECTION00041200000000000000">3.1.2 Projects with Multiple Source Files</A>
<LI><A NAME="tex2html544"
HREF="node20.html#SECTION00041300000000000000">3.1.3 Projects with Additional Libraries</A>
</UL>
<!--End of Table of Child-Links-->
<HR>
<H2><A NAME="SECTION00041000000000000000">
3.1 Compiling</A>
</H2>
<P>
<H3><A NAME="SECTION00041100000000000000">
3.1.1 Single Source File Projects</A>
</H3>
<P>
For single source file 8051 projects the process is very simple. Compile
your programs with the following command <I><B>&#34;sdcc
sourcefile.c&#34;.</B></I> This will compile, assemble and link your
source file. Output files are as follows
<BR>
<BR>
sourcefile.asm - Assembler source file created by the compiler
<BR>
sourcefile.lst - Assembler listing file created by the Assembler
<BR>
sourcefile.rst - Assembler listing file updated with linkedit information,
created by linkage editor
<BR>
sourcefile.sym - symbol listing for the sourcefile, created by the
assembler
<BR>
sourcefile.rel - Object file created by the assembler, input to Linkage
editor
<BR>
sourcefile.map - The memory map for the load module, created by the
Linker
<BR>
sourcefile.ihx - The load module in Intel hex format (you can select
the Motorola S19 format with -out-fmt-s19)
<BR>
sourcefile.cdb - An optional file (with -debug) containing debug
information
<BR>
<P>
<H3><A NAME="SECTION00041200000000000000">
3.1.2 Projects with Multiple Source Files</A>
</H3>
<P>
SDCC can compile only ONE file at a time. Let us for example assume
that you have a project containing the following files:
<BR>
<BR>
foo1.c (contains some functions)
<BR>
foo2.c (contains some more functions)
<BR>
foomain.c (contains more functions and the function main)
<BR>
<BR>
The first two files will need to be compiled separately with the commands:
<BR>
<BR>
<I><B>sdcc&nbsp;-c&nbsp;foo1.c</B></I>
<BR>
<I><B>sdcc&nbsp;-c&nbsp;foo2.c</B></I>
<BR>
<BR>
Then compile the source file containing the <I>main()</I> function
and link the files together with the following command:
<BR>
<BR>
<I><B>sdcc&nbsp;foomain.c&nbsp;foo1.rel&nbsp;foo2.rel</B></I>
<BR>
<BR>
Alternatively, <I>foomain.c</I> can be separately compiled as well:
<BR>
<BR>
<I><B>sdcc&nbsp;-c&nbsp;foomain.c</B></I>
<BR>
<I><B>sdcc foomain.rel foo1.rel foo2.rel</B></I>
<BR>
<BR>
The file containing the <I>main()</I> function <SMALL>MUST</SMALL>
be the <SMALL>FIRST</SMALL> file specified in the command line, since the
linkage editor processes file in the order they are presented to it.
<P>
<H3><A NAME="SECTION00041300000000000000">
3.1.3 Projects with Additional Libraries</A>
</H3>
<P>
Some reusable routines may be compiled into a library, see the documentation
for the assembler and linkage editor (which are in &lt;installdir&gt;/share/sdcc/doc)
for how to create a <I>.lib</I> library file. Libraries created in
this manner can be included in the command line. Make sure you include
the -L &lt;library-path&gt; 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 <I>foomain.c</I> and a library <I>foolib.lib</I>
in the directory <I>mylib</I> (if that is not the same as your current
project):
<BR>
<BR>
<I><B>sdcc foomain.c foolib.lib -L mylib</B></I>
<BR>
<BR>
Note here that <I>mylib</I> must be an absolute path name.
<BR>
<BR>
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 <I>libsdcc.lib</I>
in the directory &lt;installdir&gt;/share/lib/small.
<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html540"
HREF="node21.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
<A NAME="tex2html534"
HREF="node19.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
<A NAME="tex2html528"
HREF="node19.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
<A NAME="tex2html536"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
<A NAME="tex2html538"
HREF="node61.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
<BR>
<B> Next:</B> <A NAME="tex2html541"
HREF="node21.html">3.2 Command Line Options</A>
<B> Up:</B> <A NAME="tex2html535"
HREF="node19.html">3. Using SDCC</A>
<B> Previous:</B> <A NAME="tex2html529"
HREF="node19.html">3. Using SDCC</A>
&nbsp <B> <A NAME="tex2html537"
HREF="node1.html">Contents</A></B>
&nbsp <B> <A NAME="tex2html539"
HREF="node61.html">Index</A></B>
<!--End of Navigation Panel-->
<ADDRESS>
<I>Johan Knol</I>
<BR><I>2001-07-13</I>
</ADDRESS>
</BODY>
</HTML>