1<html lang="en"> 2<head> 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"> 9<!-- 10Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 111999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 12 13 Permission is granted to copy, distribute and/or modify this document 14under the terms of the GNU Free Documentation License, Version 1.2 or 15any later version published by the Free Software Foundation; with no 16Invariant Sections, the Front-Cover texts being (a) (see below), and 17with the Back-Cover Texts being (b) (see below). A copy of the 18license is included in the section entitled "GNU Free Documentation License". 19 20(a) The FSF's Front-Cover Text is: 21 22 A GNU Manual 23 24(b) The FSF's Back-Cover Text is: 25 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--></style> 40</head> 41<body> 42<h1 class="settitle">Installing GCC: Building</h1> 43<a name="index-Installing-GCC_003a-Building-1"></a> 44Now that GCC is configured, you are ready to build the compiler and 45runtime libraries. 46 47 <p>We <strong>highly</strong> recommend that GCC be built using GNU make; 48other versions may work, then again they might not. 49GNU make is required for compiling GNAT (the Ada compiler) and the Java 50runtime library. 51 52 <p>(For example, many broken versions of make will fail if you use the 53recommended setup where <var>objdir</var> is different from <var>srcdir</var>. 54Other broken versions may recompile parts of the compiler when 55installing the compiler.) 56 57 <p>Some commands executed when making the compiler may fail (return a 58nonzero status) and be ignored by <span class="command">make</span>. These failures, which 59are often due to files that were not found, are expected, and can safely 60be ignored. 61 62 <p>It is normal to have compiler warnings when compiling certain files. 63Unless you are a GCC developer, you can generally ignore these warnings 64unless they cause compilation to fail. 65 66 <p>On certain old systems, defining certain environment variables such as 67<span class="env">CC</span> can interfere with the functioning of <span class="command">make</span>. 68 69 <p>If you encounter seemingly strange errors when trying to build the 70compiler in a directory other than the source directory, it could be 71because you have previously configured the compiler in the source 72directory. Make sure you have done all the necessary preparations. 73 74 <p>If you build GCC on a BSD system using a directory stored in an old System 75V file system, problems may occur in running <span class="command">fixincludes</span> if the 76System V file system doesn't support symbolic links. These problems 77result in a failure to fix the declaration of <code>size_t</code> in 78<span class="file">sys/types.h</span>. If you find that <code>size_t</code> is a signed type and 79that type mismatches occur, this could be the cause. 80 81 <p>The solution is not to use such a directory for building GCC. 82 83 <p>When building from CVS or snapshots, or if you modify parser sources, 84you need the Bison parser generator installed. Any version 1.25 or 85later should work; older versions may also work. If you do not modify 86parser sources, releases contain the Bison-generated files and you do 87not need Bison installed to build them. 88 89 <p>When building from CVS or snapshots, or if you modify Texinfo 90documentation, you need version 4.2 or later of Texinfo installed if you 91want Info documentation to be regenerated. Releases contain Info 92documentation pre-built for the unmodified documentation in the release. 93 94<h3 class="section"><a name="TOC0"></a>0.1 Building a native compiler</h3> 95 96<p>For a native build issue the command <span class="samp">make bootstrap</span>. This 97will build the entire GCC system, which includes the following steps: 98 99 <ul> 100<li>Build host tools necessary to build the compiler such as texinfo, bison, 101gperf. 102 103 <li>Build target tools for use by the compiler such as binutils (bfd, 104binutils, gas, gprof, ld, and opcodes) 105if they have been individually linked 106or moved into the top level GCC source tree before configuring. 107 108 <li>Perform a 3-stage bootstrap of the compiler. 109 110 <li>Perform a comparison test of the stage2 and stage3 compilers. 111 112 <li>Build runtime libraries using the stage3 compiler from the previous step. 113 114 </ul> 115 116 <p>If you are short on disk space you might consider <span class="samp">make 117bootstrap-lean</span> instead. This is identical to <span class="samp">make 118bootstrap</span> except that object files from the stage1 and 119stage2 of the 3-stage bootstrap of the compiler are deleted as 120soon as they are no longer needed. 121 122 <p>If you want to save additional space during the bootstrap and in 123the final installation as well, you can build the compiler binaries 124without debugging information as in the following example. This will save 125roughly 40% of disk space both for the bootstrap and the final installation. 126(Libraries will still contain debugging information.) 127 128<pre class="example"> make CFLAGS='-O' LIBCFLAGS='-g -O2' \ 129 LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap 130</pre> 131 <p>If you wish to use non-default GCC flags when compiling the stage2 and 132stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when doing 133<span class="samp">make bootstrap</span>. Non-default optimization flags are less well 134tested here than the default of <span class="samp">-g -O2</span>, but should still work. 135In a few cases, you may find that you need to specify special flags such 136as <span class="option">-msoft-float</span> here to complete the bootstrap; or, if the 137native compiler miscompiles the stage1 compiler, you may need to work 138around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts of the 139stage1 compiler that were miscompiled, or by using <span class="samp">make 140bootstrap4</span> to increase the number of stages of bootstrap. 141 142 <p>If you used the flag <span class="option">--enable-languages=...</span> to restrict 143the compilers to be built, only those you've actually enabled will be 144built. This will of course only build those runtime libraries, for 145which the particular compiler has been built. Please note, 146that re-defining <span class="env">LANGUAGES</span> when calling <span class="samp">make bootstrap</span> 147<strong>does not</strong> work anymore! 148 149 <p>If the comparison of stage2 and stage3 fails, this normally indicates 150that the stage2 compiler has compiled GCC incorrectly, and is therefore 151a potentially serious bug which you should investigate and report. (On 152a few systems, meaningful comparison of object files is impossible; they 153always appear “different”. If you encounter this problem, you will 154need to disable comparison in the <span class="file">Makefile</span>.) 155 156<h3 class="section"><a name="TOC1"></a>0.2 Building a cross compiler</h3> 157 158<p>We recommend reading the 159<a href="http://www.objsw.com/CrossGCC/">crossgcc FAQ</a> 160for information about building cross compilers. 161 162 <p>When building a cross compiler, it is not generally possible to do a 1633-stage bootstrap of the compiler. This makes for an interesting problem 164as parts of GCC can only be built with GCC. 165 166 <p>To build a cross compiler, we first recommend building and installing a 167native compiler. You can then use the native GCC compiler to build the 168cross compiler. The installed native compiler needs to be GCC version 1692.95 or later. 170 171 <p>Assuming you have already installed a native copy of GCC and configured 172your cross compiler, issue the command <span class="command">make</span>, which performs the 173following steps: 174 175 <ul> 176<li>Build host tools necessary to build the compiler such as texinfo, bison, 177gperf. 178 179 <li>Build target tools for use by the compiler such as binutils (bfd, 180binutils, gas, gprof, ld, and opcodes) 181if they have been individually linked or moved into the top level GCC source 182tree before configuring. 183 184 <li>Build the compiler (single stage only). 185 186 <li>Build runtime libraries using the compiler from the previous step. 187</ul> 188 189 <p>Note that if an error occurs in any step the make process will exit. 190 191<h3 class="section"><a name="TOC2"></a>0.3 Building in parallel</h3> 192 193<p>You can use <span class="samp">make bootstrap MAKE="make -j 2" -j 2</span>, or just 194<span class="samp">make -j 2 bootstrap</span> for GNU Make 3.79 and above, instead of 195<span class="samp">make bootstrap</span> to build GCC in parallel. 196You can also specify a bigger number, and in most cases using a value 197greater than the number of processors in your machine will result in 198fewer and shorter I/O latency hits, thus improving overall throughput; 199this is especially true for slow drives and network filesystems. 200 201<h3 class="section"><a name="TOC3"></a>0.4 Building the Ada compiler</h3> 202 203<p>In order to build GNAT, the Ada compiler, you need a working GNAT 204compiler (GNAT version 3.13 or later, or GCC version 3.1 or later), 205since the Ada front end is written in Ada (with some 206GNAT-specific extensions), and GNU make. 207 208 <p>However, you do not need a full installation of GNAT, just the GNAT 209binary <span class="file">gnat1</span>, a copy of <span class="file">gnatbind</span>, and a compiler driver 210which can deal with Ada input (by invoking the <span class="file">gnat1</span> binary). 211You can specify this compiler driver by setting the <span class="env">ADAC</span> 212environment variable at the configure step. <span class="command">configure</span> can 213detect the driver automatically if it has got a common name such as 214<span class="command">gcc</span> or <span class="command">gnatgcc</span>. Of course, you still need a working 215C compiler (the compiler driver can be different or not). 216<span class="command">configure</span> does not test whether the GNAT installation works 217and has a sufficiently recent version; if too old a GNAT version is 218installed, the build will fail unless <span class="option">--enable-languages</span> is 219used to disable building the Ada front end. 220 221 <p>Additional build tools (such as <span class="command">gnatmake</span>) or a working GNAT 222run-time library installation are usually <em>not</em> required. However, 223if you want to bootstrap the compiler using a minimal version of GNAT, 224you have to issue the following commands before invoking <span class="samp">make 225bootstrap</span> (this assumes that you start with an unmodified and consistent 226source distribution): 227 228<pre class="example"> cd <var>srcdir</var>/gcc/ada 229 touch treeprs.ads [es]info.h nmake.ad[bs] 230</pre> 231 <p>At the moment, the GNAT library and several tools for GNAT are not built 232by <span class="samp">make bootstrap</span>. You have to invoke 233<span class="samp">make gnatlib_and_tools</span> in the <var>objdir</var><span class="file">/gcc</span> 234subdirectory before proceeding with the next steps. 235 236 <p>For example, you can build a native Ada compiler by issuing the 237following commands (assuming <span class="command">make</span> is GNU make): 238 239<pre class="example"> cd <var>objdir</var> 240 <var>srcdir</var>/configure --enable-languages=c,ada 241 cd <var>srcdir</var>/gcc/ada 242 touch treeprs.ads [es]info.h nmake.ad[bs] 243 cd <var>objdir</var> 244 make bootstrap 245 cd gcc 246 make gnatlib_and_tools 247 cd .. 248</pre> 249 <p>Currently, when compiling the Ada front end, you cannot use the parallel 250build feature described in the previous section. 251 252 <p><hr /> 253<p><a href="./index.html">Return to the GCC Installation page</a> 254 255<!-- ***Testing***************************************************************** --> 256<!-- ***Final install*********************************************************** --> 257<!-- ***Binaries**************************************************************** --> 258<!-- ***Specific**************************************************************** --> 259<!-- ***Old documentation****************************************************** --> 260<!-- ***GFDL******************************************************************** --> 261<!-- *************************************************************************** --> 262<!-- Part 6 The End of the Document --> 263</body></html> 264 265