3 <title>Installing GCC: Building
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Installing GCC: Building">
6 <meta name=
"generator" content=
"makeinfo 4.7">
7 <link title=
"Top" rel=
"top" href=
"#Top">
8 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home" title=
"Texinfo Homepage">
10 Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
11 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
13 Permission is granted to copy, distribute and/or modify this document
14 under the terms of the GNU Free Documentation License, Version 1.2 or
15 any later version published by the Free Software Foundation; with no
16 Invariant Sections, the Front-Cover texts being (a) (see below), and
17 with the Back-Cover Texts being (b) (see below). A copy of the
18 license is included in the section entitled "GNU Free Documentation License".
20 (a) The FSF's Front-Cover Text is:
24 (b) The FSF's Back-Cover Text is:
26 You have freedom to copy and modify this GNU Manual, like GNU
27 software. Copies published by the Free Software Foundation raise
28 funds for GNU development.-->
29 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
30 <style type=
"text/css"><!--
31 pre
.display
{ font-family:inherit
}
32 pre
.format
{ font-family:inherit
}
33 pre
.smalldisplay
{ font-family:inherit
; font-size:smaller
}
34 pre
.smallformat
{ font-family:inherit
; font-size:smaller
}
35 pre
.smallexample
{ font-size:smaller
}
36 pre
.smalllisp
{ font-size:smaller
}
37 span
.sc
{ font-variant:small-caps
}
38 span
.roman
{ font-family: serif
; font-weight: normal
; }
42 <h1 class=
"settitle">Installing GCC: Building
</h1>
43 <a name=
"index-Installing-GCC_003a-Building-1"></a>
44 Now that GCC is configured, you are ready to build the compiler and
47 <p>Some commands executed when making the compiler may fail (return a
48 nonzero status) and be ignored by
<span class=
"command">make
</span>. These failures, which
49 are often due to files that were not found, are expected, and can safely
52 <p>It is normal to have compiler warnings when compiling certain files.
53 Unless you are a GCC developer, you can generally ignore these warnings
54 unless they cause compilation to fail. Developers should attempt to fix
55 any warnings encountered, however they can temporarily continue past
56 warnings-as-errors by specifying the configure flag
57 <span class=
"option">--disable-werror
</span>.
59 <p>On certain old systems, defining certain environment variables such as
60 <span class=
"env">CC
</span> can interfere with the functioning of
<span class=
"command">make
</span>.
62 <p>If you encounter seemingly strange errors when trying to build the
63 compiler in a directory other than the source directory, it could be
64 because you have previously configured the compiler in the source
65 directory. Make sure you have done all the necessary preparations.
67 <p>If you build GCC on a BSD system using a directory stored in an old System
68 V file system, problems may occur in running
<span class=
"command">fixincludes
</span> if the
69 System V file system doesn't support symbolic links. These problems
70 result in a failure to fix the declaration of
<code>size_t
</code> in
71 <span class=
"file">sys/types.h
</span>. If you find that
<code>size_t
</code> is a signed type and
72 that type mismatches occur, this could be the cause.
74 <p>The solution is not to use such a directory for building GCC.
76 <p>When building from CVS or snapshots, or if you modify parser sources,
77 you need the Bison parser generator installed. Any version
1.25 or
78 later should work; older versions may also work. If you do not modify
79 parser sources, releases contain the Bison-generated files and you do
80 not need Bison installed to build them.
82 <p>When building from CVS or snapshots, or if you modify Texinfo
83 documentation, you need version
4.2 or later of Texinfo installed if you
84 want Info documentation to be regenerated. Releases contain Info
85 documentation pre-built for the unmodified documentation in the release.
87 <h3 class=
"section"><a name=
"TOC0"></a>0.1 Building a native compiler
</h3>
89 <p>For a native build issue the command
<span class=
"samp">make bootstrap
</span>. This
90 will build the entire GCC system, which includes the following steps:
93 <li>Build host tools necessary to build the compiler such as texinfo, bison,
96 <li>Build target tools for use by the compiler such as binutils (bfd,
97 binutils, gas, gprof, ld, and opcodes)
98 if they have been individually linked
99 or moved into the top level GCC source tree before configuring.
101 <li>Perform a
3-stage bootstrap of the compiler.
103 <li>Perform a comparison test of the stage2 and stage3 compilers.
105 <li>Build runtime libraries using the stage3 compiler from the previous step.
109 <p>If you are short on disk space you might consider
<span class=
"samp">make
110 bootstrap-lean
</span> instead. This is identical to
<span class=
"samp">make
111 bootstrap
</span> except that object files from the stage1 and
112 stage2 of the
3-stage bootstrap of the compiler are deleted as
113 soon as they are no longer needed.
115 <p>If you want to save additional space during the bootstrap and in
116 the final installation as well, you can build the compiler binaries
117 without debugging information as in the following example. This will save
118 roughly
40% of disk space both for the bootstrap and the final installation.
119 (Libraries will still contain debugging information.)
121 <pre class=
"smallexample"> make CFLAGS='-O' LIBCFLAGS='-g -O2' \
122 LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap
124 <p>If you wish to use non-default GCC flags when compiling the stage2 and
125 stage3 compilers, set
<code>BOOT_CFLAGS
</code> on the command line when doing
126 <span class=
"samp">make bootstrap
</span>. Non-default optimization flags are less well
127 tested here than the default of
<span class=
"samp">-g -O2
</span>, but should still work.
128 In a few cases, you may find that you need to specify special flags such
129 as
<span class=
"option">-msoft-float
</span> here to complete the bootstrap; or, if the
130 native compiler miscompiles the stage1 compiler, you may need to work
131 around this, by choosing
<code>BOOT_CFLAGS
</code> to avoid the parts of the
132 stage1 compiler that were miscompiled, or by using
<span class=
"samp">make
133 bootstrap4
</span> to increase the number of stages of bootstrap.
135 <p>If you used the flag
<span class=
"option">--enable-languages=...
</span> to restrict
136 the compilers to be built, only those you've actually enabled will be
137 built. This will of course only build those runtime libraries, for
138 which the particular compiler has been built. Please note,
139 that re-defining
<span class=
"env">LANGUAGES
</span> when calling
<span class=
"samp">make bootstrap
</span>
140 <strong>does not
</strong> work anymore!
142 <p>If the comparison of stage2 and stage3 fails, this normally indicates
143 that the stage2 compiler has compiled GCC incorrectly, and is therefore
144 a potentially serious bug which you should investigate and report. (On
145 a few systems, meaningful comparison of object files is impossible; they
146 always appear
“different
”. If you encounter this problem, you will
147 need to disable comparison in the
<span class=
"file">Makefile
</span>.)
149 <h3 class=
"section"><a name=
"TOC1"></a>0.2 Building a cross compiler
</h3>
151 <p>We recommend reading the
152 <a href=
"http://www.objsw.com/CrossGCC/">crossgcc FAQ
</a>
153 for information about building cross compilers.
155 <p>When building a cross compiler, it is not generally possible to do a
156 3-stage bootstrap of the compiler. This makes for an interesting problem
157 as parts of GCC can only be built with GCC.
159 <p>To build a cross compiler, we first recommend building and installing a
160 native compiler. You can then use the native GCC compiler to build the
161 cross compiler. The installed native compiler needs to be GCC version
164 <p>Assuming you have already installed a native copy of GCC and configured
165 your cross compiler, issue the command
<span class=
"command">make
</span>, which performs the
169 <li>Build host tools necessary to build the compiler such as texinfo, bison,
172 <li>Build target tools for use by the compiler such as binutils (bfd,
173 binutils, gas, gprof, ld, and opcodes)
174 if they have been individually linked or moved into the top level GCC source
175 tree before configuring.
177 <li>Build the compiler (single stage only).
179 <li>Build runtime libraries using the compiler from the previous step.
182 <p>Note that if an error occurs in any step the make process will exit.
184 <p>If you are not building GNU binutils in the same source tree as GCC,
185 you will need a cross-assembler and cross-linker installed before
186 configuring GCC. Put them in the directory
187 <var>prefix
</var><span class=
"file">/
</span><var>target
</var><span class=
"file">/bin
</span>. Here is a table of the tools
188 you should put in this directory:
191 <dt><span class=
"file">as
</span><dd>This should be the cross-assembler.
193 <br><dt><span class=
"file">ld
</span><dd>This should be the cross-linker.
195 <br><dt><span class=
"file">ar
</span><dd>This should be the cross-archiver: a program which can manipulate
196 archive files (linker libraries) in the target machine's format.
198 <br><dt><span class=
"file">ranlib
</span><dd>This should be a program to construct a symbol table in an archive file.
201 <p>The installation of GCC will find these programs in that directory,
202 and copy or link them to the proper place to for the cross-compiler to
203 find them when run later.
205 <p>The easiest way to provide these files is to build the Binutils package.
206 Configure it with the same
<span class=
"option">--host
</span> and
<span class=
"option">--target
</span>
207 options that you use for configuring GCC, then build and install
208 them. They install their executables automatically into the proper
209 directory. Alas, they do not support all the targets that GCC
212 <p>If you are not building a C library in the same source tree as GCC,
213 you should also provide the target libraries and headers before
214 configuring GCC, specifying the directories with
215 <span class=
"option">--with-sysroot
</span> or
<span class=
"option">--with-headers
</span> and
216 <span class=
"option">--with-libs
</span>. Many targets also require
“start files
” such
217 as
<span class=
"file">crt0.o
</span> and
218 <span class=
"file">crtn.o
</span> which are linked into each executable. There may be several
219 alternatives for
<span class=
"file">crt0.o
</span>, for use with profiling or other
220 compilation options. Check your target's definition of
221 <code>STARTFILE_SPEC
</code> to find out what start files it uses.
223 <h3 class=
"section"><a name=
"TOC2"></a>0.3 Building in parallel
</h3>
225 <p>You can use
<span class=
"samp">make bootstrap
MAKE=
"make -j 2" -j
2</span>, or just
226 <span class=
"samp">make -j
2 bootstrap
</span> for GNU Make
3.79 and above, instead of
227 <span class=
"samp">make bootstrap
</span> to build GCC in parallel.
228 You can also specify a bigger number, and in most cases using a value
229 greater than the number of processors in your machine will result in
230 fewer and shorter I/O latency hits, thus improving overall throughput;
231 this is especially true for slow drives and network filesystems.
233 <h3 class=
"section"><a name=
"TOC3"></a>0.4 Building the Ada compiler
</h3>
235 <p>In order to build GNAT, the Ada compiler, you need a working GNAT
236 compiler (GNAT version
3.14 or later, or GCC version
3.1 or later),
237 including GNAT tools such as
<span class=
"command">gnatmake
</span> and
<span class=
"command">gnatlink
</span>,
238 since the Ada front end is written in Ada (with some
239 GNAT-specific extensions), and GNU make.
241 <p><span class=
"command">configure
</span> does not test whether the GNAT installation works
242 and has a sufficiently recent version; if too old a GNAT version is
243 installed, the build will fail unless
<span class=
"option">--enable-languages
</span> is
244 used to disable building the Ada front end.
246 <p>At the moment, the GNAT library and several tools for GNAT are not built
247 by
<span class=
"samp">make bootstrap
</span>. For a native build, you have to invoke
248 <span class=
"samp">make gnatlib_and_tools
</span> in the
<var>objdir
</var><span class=
"file">/gcc
</span>
249 subdirectory before proceeding with the next steps.
250 For a cross build, you need to invoke
251 <span class=
"samp">make gnatlib cross-gnattools ada.all.cross
</span>. For a canadian
252 cross you only need to invoke
<span class=
"samp">make cross-gnattools
</span>; the GNAT
253 library would be the same as the one built for the cross compiler.
255 <p>For example, you can build a native Ada compiler by issuing the
256 following commands (assuming
<span class=
"command">make
</span> is GNU make):
258 <pre class=
"smallexample"> cd
<var>objdir
</var>
259 <var>srcdir
</var>/configure --enable-languages=c,ada
263 make gnatlib_and_tools
266 <p>Currently, when compiling the Ada front end, you cannot use the parallel
267 build feature described in the previous section.
269 <h3 class=
"section"><a name=
"TOC4"></a>0.5 Building with profile feedback
</h3>
271 <p>It is possible to use profile feedback to optimize the compiler itself. This
272 should result in a faster compiler binary. Experiments done on x86 using gcc
273 3.3 showed approximately
7 percent speedup on compiling C programs. To
274 bootstrap compiler with profile feedback, use
<code>make profiledbootstrap
</code>.
276 <p>When
<span class=
"samp">make profiledbootstrap
</span> is run, it will first build a
<code>stage1
</code>
277 compiler. This compiler is used to build a
<code>stageprofile
</code> compiler
278 instrumented to collect execution counts of instruction and branch
279 probabilities. Then runtime libraries are compiled with profile collected.
280 Finally a
<code>stagefeedback
</code> compiler is built using the information collected.
282 <p>Unlike
<span class=
"samp">make bootstrap
</span> several additional restrictions apply. The
283 compiler used to build
<code>stage1
</code> needs to support a
64-bit integral type.
284 It is recommended to only use GCC for this. Also parallel make is currently
285 not supported since collisions in profile collecting may occur.
288 <p><a href=
"./index.html">Return to the GCC Installation page
</a>
290 <!-- ***Testing***************************************************************** -->
291 <!-- ***Final install*********************************************************** -->
292 <!-- ***Binaries**************************************************************** -->
293 <!-- ***Specific**************************************************************** -->
294 <!-- ***Old documentation****************************************************** -->
295 <!-- ***GFDL******************************************************************** -->
296 <!-- *************************************************************************** -->
297 <!-- Part 6 The End of the Document -->