ef2fc5b90acd1cb1b356a9adbcbbbf522880bc4e
[fw/sdcc] / doc / SDCCUdoc-3.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
5  <TITLE>SDCC Compiler User Guide: Compiling.</TITLE>
6  <LINK HREF="SDCCUdoc-4.html" REL=next>
7  <LINK HREF="SDCCUdoc-2.html" REL=previous>
8  <LINK HREF="SDCCUdoc.html#toc3" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-4.html">Next</A>
12 <A HREF="SDCCUdoc-2.html">Previous</A>
13 <A HREF="SDCCUdoc.html#toc3">Contents</A>
14 <HR>
15 <H2><A NAME="Compiling"></A> <A NAME="s3">3. Compiling.</A> </H2>
16
17 <H2><A NAME="One Source File"></A> <A NAME="ss3.1">3.1 Single Source file projects.</A>
18  </H2>
19
20 <P>For single source file projects the process is very simple. Compile your
21 programs with the following command
22 <P>
23 <PRE>
24 sdcc sourcefile.c
25  
26 </PRE>
27 <P>The above command will compile ,assemble and link your source file. Output
28 files are as follows.
29 <P>
30 <UL>
31 <LI>sourcefile.asm - Assembler source file created by the compiler</LI>
32 <LI>sourcefile.lst - Assembler listing file created by the Assembler</LI>
33 <LI>sourcefile.rst - Assembler listing file updated with linkedit information
34 , created by linkage editor</LI>
35 <LI>sourcefile.sym - symbol listing for the sourcefile, created by the assembler.</LI>
36 <LI>sourcefile.rel - Object file created by the assembler, input to Linkage
37 editor.</LI>
38 <LI>sourcefile.map - The memory map for the load module, created by the Linker.</LI>
39 <LI>sourcefile.&lt;ihx | s19&gt; - The load module : ihx - Intel hex format
40 (default ), s19 - Motorola S19 format when compiler option --out-fmt-s19 is
41 used.</LI>
42 </UL>
43 <H2><A NAME="ss3.2">3.2 Projects with multiple source files.</A>
44  </H2>
45
46 <P>SDCC can compile only ONE file at a time. Let us for example assume that
47 you have a project containing the following files.
48 <P>
49 <PRE>
50 foo1.c ( contains some functions )foo2.c (contains some more functions)foomain.c (contains more functions and the function main)
51  
52 </PRE>
53 <P>The first two files will need to be compiled separately with the commands
54 <P>
55 <PRE>
56 sdcc -c foo1.csdcc -c foo2.c
57  
58 </PRE>
59 <P>Then compile the source file containing main and link the other files together
60 with the following command.
61 <P>
62 <PRE>
63 sdcc foomain.c foo1.rel foo2.rel
64  
65 </PRE>
66 <P>Alternatively foomain.c can be separately compiled as well
67 <P>
68 <PRE>
69 sdcc -c foomain.c sdcc foomain.rel foo1.rel foo2.rel
70  
71 </PRE>
72 <P>The file containing the main function MUST be the FIRST file specified
73 in the command line , since the linkage editor processes file in the order
74 they are presented to it.
75 <H2><A NAME="ss3.3">3.3 Projects with additional libraries.</A>
76  </H2>
77
78 <P>Some reusable routines may be compiled into a library, see the documentation
79 for the assembler and linkage editor in the directory SDCCDIR/asxxxx/asxhtm.htm
80 this describes how to create a .lib library file, the libraries created in
81 this manner may be included using the command line, make sure you include the
82 -L &lt;library-path&gt; option to tell the linker where to look for these files.
83 Here is an example, assuming you have the source file 'foomain.c' and a library
84 'foolib.lib' in the directory 'mylib'.
85 <P>
86 <PRE>
87 sdcc foomain.c foolib.lib -L mylib
88  
89 </PRE>
90 <P>Note here that 'mylib' must be an absolute path name.
91 <P>The view of the way the linkage editor processes the library files, it
92 is recommended that you put each source routine in a separate file and combine
93 them using the .lib file. For an example see the standard library file 'libsdcc.lib'
94 in the directory SDCCDIR/sdcc51lib.
95 <HR>
96 <A HREF="SDCCUdoc-4.html">Next</A>
97 <A HREF="SDCCUdoc-2.html">Previous</A>
98 <A HREF="SDCCUdoc.html#toc3">Contents</A>
99 </BODY>
100 </HTML>