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.8">
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, 2005 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
; }
39 span
.sansserif
{ font-family:sans-serif
; font-weight:normal
; }
43 <h1 class=
"settitle">Installing GCC: Building
</h1>
44 <a name=
"index-Installing-GCC_003a-Building-1"></a>
45 Now that GCC is configured, you are ready to build the compiler and
48 <p>Some commands executed when making the compiler may fail (return a
49 nonzero status) and be ignored by
<samp><span class=
"command">make
</span></samp>. These failures, which
50 are often due to files that were not found, are expected, and can safely
53 <p>It is normal to have compiler warnings when compiling certain files.
54 Unless you are a GCC developer, you can generally ignore these warnings
55 unless they cause compilation to fail. Developers should attempt to fix
56 any warnings encountered, however they can temporarily continue past
57 warnings-as-errors by specifying the configure flag
58 <samp><span class=
"option">--disable-werror
</span></samp>.
60 <p>On certain old systems, defining certain environment variables such as
61 <samp><span class=
"env">CC
</span></samp> can interfere with the functioning of
<samp><span class=
"command">make
</span></samp>.
63 <p>If you encounter seemingly strange errors when trying to build the
64 compiler in a directory other than the source directory, it could be
65 because you have previously configured the compiler in the source
66 directory. Make sure you have done all the necessary preparations.
68 <p>If you build GCC on a BSD system using a directory stored in an old System
69 V file system, problems may occur in running
<samp><span class=
"command">fixincludes
</span></samp> if the
70 System V file system doesn't support symbolic links. These problems
71 result in a failure to fix the declaration of
<code>size_t
</code> in
72 <samp><span class=
"file">sys/types.h
</span></samp>. If you find that
<code>size_t
</code> is a signed type and
73 that type mismatches occur, this could be the cause.
75 <p>The solution is not to use such a directory for building GCC.
77 <p>When building from SVN or snapshots, or if you modify parser sources,
78 you need the Bison parser generator installed. 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 SVN 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 `
<samp><span class=
"samp">make bootstrap
</span></samp>'. 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 `
<samp><span class=
"samp">make
110 bootstrap-lean
</span></samp>' instead. This is identical to `
<samp><span class=
"samp">make
111 bootstrap
</span></samp>' 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 `
<samp><span class=
"samp">make bootstrap
</span></samp>'. Non-default optimization flags are less well
127 tested here than the default of `
<samp><span class=
"samp">-g -O2
</span></samp>', but should still work.
128 In a few cases, you may find that you need to specify special flags such
129 as
<samp><span class=
"option">-msoft-float
</span></samp> 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 `
<samp><span class=
"samp">make
133 bootstrap4
</span></samp>' to increase the number of stages of bootstrap.
135 <p>Note that using non-standard
<code>CFLAGS
</code> can cause bootstrap to fail in
136 <samp><span class=
"file">libiberty
</span></samp>, if these trigger a warning with the new compiler. For
137 example using `
<samp><span class=
"samp">-O2 -g -mcpu=i686
</span></samp>' on
<code>i686-pc-linux-gnu
</code> will
138 cause bootstrap failure as
<samp><span class=
"option">-mcpu=
</span></samp> is deprecated in
3.4.0 and above.
140 <p>If you used the flag
<samp><span class=
"option">--enable-languages=...
</span></samp> to restrict
141 the compilers to be built, only those you've actually enabled will be
142 built. This will of course only build those runtime libraries, for
143 which the particular compiler has been built. Please note,
144 that re-defining
<samp><span class=
"env">LANGUAGES
</span></samp> when calling `
<samp><span class=
"samp">make bootstrap
</span></samp>'
145 <strong>does not
</strong> work anymore!
147 <p>If the comparison of stage2 and stage3 fails, this normally indicates
148 that the stage2 compiler has compiled GCC incorrectly, and is therefore
149 a potentially serious bug which you should investigate and report. (On
150 a few systems, meaningful comparison of object files is impossible; they
151 always appear
“different
”. If you encounter this problem, you will
152 need to disable comparison in the
<samp><span class=
"file">Makefile
</span></samp>.)
154 <h3 class=
"section"><a name=
"TOC1"></a>0.2 Building a cross compiler
</h3>
156 <p>When building a cross compiler, it is not generally possible to do a
157 3-stage bootstrap of the compiler. This makes for an interesting problem
158 as parts of GCC can only be built with GCC.
160 <p>To build a cross compiler, we first recommend building and installing a
161 native compiler. You can then use the native GCC compiler to build the
162 cross compiler. The installed native compiler needs to be GCC version
165 <p>Assuming you have already installed a native copy of GCC and configured
166 your cross compiler, issue the command
<samp><span class=
"command">make
</span></samp>, which performs the
170 <li>Build host tools necessary to build the compiler.
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 <samp><var>prefix
</var><span class=
"file">/
</span><var>target
</var><span class=
"file">/bin
</span></samp>. Here is a table of the tools
188 you should put in this directory:
191 <dt><samp><span class=
"file">as
</span></samp><dd>This should be the cross-assembler.
193 <br><dt><samp><span class=
"file">ld
</span></samp><dd>This should be the cross-linker.
195 <br><dt><samp><span class=
"file">ar
</span></samp><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><samp><span class=
"file">ranlib
</span></samp><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
<samp><span class=
"option">--host
</span></samp> and
<samp><span class=
"option">--target
</span></samp>
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 <samp><span class=
"option">--with-sysroot
</span></samp> or
<samp><span class=
"option">--with-headers
</span></samp> and
216 <samp><span class=
"option">--with-libs
</span></samp>. Many targets also require
“start files
” such
217 as
<samp><span class=
"file">crt0.o
</span></samp> and
218 <samp><span class=
"file">crtn.o
</span></samp> which are linked into each executable. There may be several
219 alternatives for
<samp><span class=
"file">crt0.o
</span></samp>, 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 `
<samp><span class=
"samp">make bootstrap
MAKE=
"make -j 2" -j
2</span></samp>', or just
226 `
<samp><span class=
"samp">make -j
2 bootstrap
</span></samp>' for GNU Make
3.79 and above, instead of
227 `
<samp><span class=
"samp">make bootstrap
</span></samp>' 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
<samp><span class=
"command">gnatmake
</span></samp> and
<samp><span class=
"command">gnatlink
</span></samp>,
238 since the Ada front end is written in Ada (with some
239 GNAT-specific extensions), and GNU make.
241 <p><samp><span class=
"command">configure
</span></samp> 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
<samp><span class=
"option">--enable-languages
</span></samp> is
244 used to disable building the Ada front end.
246 <h3 class=
"section"><a name=
"TOC4"></a>0.5 Building with profile feedback
</h3>
248 <p>It is possible to use profile feedback to optimize the compiler itself. This
249 should result in a faster compiler binary. Experiments done on x86 using gcc
250 3.3 showed approximately
7 percent speedup on compiling C programs. To
251 bootstrap compiler with profile feedback, use
<code>make profiledbootstrap
</code>.
253 <p>When `
<samp><span class=
"samp">make profiledbootstrap
</span></samp>' is run, it will first build a
<code>stage1
</code>
254 compiler. This compiler is used to build a
<code>stageprofile
</code> compiler
255 instrumented to collect execution counts of instruction and branch
256 probabilities. Then runtime libraries are compiled with profile collected.
257 Finally a
<code>stagefeedback
</code> compiler is built using the information collected.
259 <p>Unlike `
<samp><span class=
"samp">make bootstrap
</span></samp>' several additional restrictions apply. The
260 compiler used to build
<code>stage1
</code> needs to support a
64-bit integral type.
261 It is recommended to only use GCC for this. Also parallel make is currently
262 not supported since collisions in profile collecting may occur.
265 <p><a href=
"./index.html">Return to the GCC Installation page
</a>
267 <!-- ***Testing***************************************************************** -->
268 <!-- ***Final install*********************************************************** -->
269 <!-- ***Binaries**************************************************************** -->
270 <!-- ***Specific**************************************************************** -->
271 <!-- ***Old documentation****************************************************** -->
272 <!-- ***GFDL******************************************************************** -->
273 <!-- *************************************************************************** -->
274 <!-- Part 6 The End of the Document -->