Installing GCC 简单方法

Installing GCC

This page is intended to offer guidance to avoid some common problems when installing GCC, the official installation docs are in the Installing GCC section of the main GCC documentation. N.B. those installation docs refer to the development trunk, the installation instructions for released versions are included in the release sources.

For most people the easiest way to install GCC is to install a package made for your operating system. The GCC project does not provide pre-built binaries of GCC, only source code, but all GNU/Linux distributions include packages for GCC. The BSD-based systems include GCC in their ports collections. For other operating systems the Installing GCC: Binaries page lists some third-party sources of GCC binaries.

If you cannot find suitable binaries for your system, or you need a newer version than is available, you will need to build GCC from source in order to install it.

 

Building GCC

Many people rush into trying to build GCC without reading the installation docs properly and make one or more of these common mistakes:

  • do not run ./configure, this is not supported, you need to run configure from outside the source directory (this is a FAQ)

  • if GCC links dynamically to the GMP, MPFR or MPC support libraries then the relevant shared libraries must be in the dynamic linker's path, both when building gcc and when using the installed compiler (this is also a FAQ)

 

Support libraries

See Installing GCC: Prequisites for the software required to build GCC. If you do not have the GMP, MPFR and MPC support libraries already installed as part of your operating system then there are two simple ways to proceed, and one difficult, error-prone way. For some reason most people choose the difficult way. The easy ways are:

  • If it provides sufficiently recent versions, use your OS package management system to install the support libraries in standard system locations. For Debian-based systems, including Ubuntu, you should install the packages libgmp-devlibmpfr-dev and libmpc-dev. For RPM-based systems, including Fedora and SUSE, you should install gmp-develmpfr-devel and libmpc-devel (or mpc-devel on SUSE) packages. The packages will install the libraries and headers in standard system directories so they can be found automatically when building GCC.

  • Alternatively, after extracting the GCC source archive, simply run the ./contrib/download_prerequisites script in the GCC source directory. That will download the support libraries and create symlinks, causing them to be built automatically as part of the GCC build process. Set GRAPHITE_LOOP_OPT=yes in the script if you want to build GCC with the Graphite loop optimizations.

The difficult way, which is not recommended, is to download the sources for GMP, MPFR and MPC, then configure and install each of them in non-standard locations, then configure GCC with --with-gmp=/some/silly/path/gmp --with-mpfr=/some/silly/path/mpfr --with-mpc=/some/silly/path/mpc, then be forced to set LD_LIBRARY_PATH=/some/silly/path/gmp:/some/silly/path/mpfr:/some/silly/path/mpc/lib in your environment forever. This is silly and causes major problems for anyone who doesn't understand how dynamic linkers find libraries at runtime. Do not do this. If building GCC fails when using any of the --with-gmp or --with-mpfr or --with-mpc options then you probably shouldn't be using them.

 

Configuration

See Installing GCC: Configuration for the full documentation. A major benefit of running srcdir/configure from outside the source directory (instead of running ./configure) is that the source directory will not be modified in any way, so if your build fails or you want to re-configure and build again, you simply delete everything in the objdir and start again.

For example, configuring and building GCC 4.6.2 should be as simple as:

tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=$HOME/gcc-4.6.2 
make
make install

If your build fails and your configure command has lots of complicated options you should try removing options and keep it simple. Do not add lots of configure options you don't understand, they might be the reason your build fails.

 

附: ./configure --enable-languages=c,c++ --disable-multilib  

posted @ 2013-09-05 22:49  Monn  阅读(844)  评论(0编辑  收藏  举报