source: public/doc/gnu-c/Compilation.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 6.0 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Compilation (GNU C Language Manual)</title>
23
24<meta name="description" content="Compilation (GNU C Language Manual)">
25<meta name="keywords" content="Compilation (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="index.html" rel="up" title="Top">
33<link href="Directing-Compilation.html" rel="next" title="Directing Compilation">
34<link href="Further-Reading.html" rel="prev" title="Further Reading">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Compilation"></span><div class="header">
59<p>
60Next: <a href="Directing-Compilation.html" accesskey="n" rel="next">Directing Compilation</a>, Previous: <a href="Floating-Point-in-Depth.html" accesskey="p" rel="prev">Floating Point in Depth</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Compilation-1"></span><h2 class="chapter">29 Compilation</h2>
64<span id="index-object-file"></span>
65<span id="index-compilation-module"></span>
66<span id="index-make-rules"></span>
67
68<p>Early in the manual we explained how to compile a simple C program
69that consists of a single source file (see <a href="Compile-Example.html">Compile Example</a>).
70However, we handle only short programs that way. A typical C program
71consists of many source files, each of which is a separate
72<em>compilation module</em>&mdash;meaning that it has to be compiled
73separately.
74</p>
75<p>The full details of how to compile with GCC are documented in xxxx.
76Here we give only a simple introduction.
77</p>
78<p>These are the commands to compile two compilation modules,
79<samp>foo.c</samp> and <samp>bar.c</samp>, with a command for each module:
80</p>
81<div class="example">
82<pre class="example">gcc -c -O -g foo.c
83gcc -c -O -g bar.c
84</pre></div>
85
86<p>In these commands, <samp>-g</samp> says to generate debugging information,
87<samp>-O</samp> says to do some optimization, and <samp>-c</samp> says to put
88the compiled code for that module into a corresponding <em>object
89file</em> and go no further. The object file for <samp>foo.c</samp> is called
90<samp>foo.o</samp>, and so on.
91</p>
92<p>If you wish, you can specify the additional options <samp>-Wformat
93-Wparenthesis -Wstrict-prototypes</samp>, which request additional warnings.
94</p>
95<p>One reason to divide a large program into multiple compilation modules
96is to control how each module can access the internals of the others.
97When a module declares a function or variable <code>extern</code>, other
98modules can access it. The other functions and variables in
99a module can&rsquo;t be accessed from outside that module.
100</p>
101<p>The other reason for using multiple modules is so that changing
102one source file does not require recompiling all of them in order
103to try the modified program. Dividing a large program into many
104substantial modules in this way typically makes recompilation much faster.
105</p>
106<span id="index-linking-object-files"></span>
107<p>After you compile all the program&rsquo;s modules, in order to run the
108program you must <em>link</em> the object files into a combined
109executable, like this:
110</p>
111<div class="example">
112<pre class="example">gcc -o foo foo.o bar.o
113</pre></div>
114
115<p>In this command, <samp>-o foo</samp> species the file name for the
116executable file, and the other arguments are the object files to link.
117Always specify the executable file name in a command that generates
118one.
119</p>
120<p>Normally we don&rsquo;t run any of these commands directly. Instead we
121write a set of <em>make rules</em> for the program, then use the
122<code>make</code> program to recompile only the source files that need to
123be recompiled.
124</p>
125
126<hr>
127<div class="header">
128<p>
129Next: <a href="Directing-Compilation.html" accesskey="n" rel="next">Directing Compilation</a>, Previous: <a href="Floating-Point-in-Depth.html" accesskey="p" rel="prev">Floating Point in Depth</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
130</div>
131
132
133
134</body>
135</html>
Note: See TracBrowser for help on using the repository browser.