NOTE: The content of this page may be outdated. Links may not be valid and the steps detailed may no longer work. This page is saved for archival purposes only.
This guide shows how to installed an alternate GCC compiler from source using Fedora Core. By using these steps you should be able to configure and install any GCC compiler you might require. You can upgrade your GCC compiler or downgrade your GCC compiler if you require.NOTE:
Certain releases of Linux distributions like Fedora Core ship with versions of the GCC compiler that may not be compatible with other software. In some cases the compiler is very new (GCC4.1 in FC5) and in other cases the compiler may be non standard (GCC2.96 in RH7.3). Usually there should not be any major problems. However many open source applications will NOT properly compile using specific versions of GCC. Additionally many applications or code bases may not fully utilize/support newer versions of GCC. Specific developers may require installing their own specific compiler. So if you do not need to compile, then this guide is unnecessary.
Multiple compilers is typically reserved for developers or those withthe need to compile for separate architectures (i.e. "cross compiling"). Redhat and Fedora have shipped with alternate compilers (both FC4 and FC5 shipped with a GCC4.x as well as GCC3.2).
Linux is convenient that you can have as many compilers as you like.
You must have at least one compiler installed in Fedora. This varies in installation from different versions of Fedora. However most installations will install one version of GCC by default. In the newer releases (for example FC4) this includes: Development Tools in the FC4 Install Process -OR- you can go to: System Settings > Add/Remove Applications > Development > Development Tools. The following is an example on FC4:
[mirandam@charon fc4]$ rpm -q gcc gcc-4.0.0-8
To install from source obtain GCC from any GCC mirror sites. It is your personal selection in choice of the version of GCC. Upon writing this draft GCC 3.4.4 is available. Try to find a mirror with the full files NOT the diff files. The following is only an example:
gcc-3.4.4.tar.bz2 26920 KB 05/19/2005 10:50:00 AM gcc-ada-3.4.4.tar.bz2 3380 KB 05/19/2005 10:50:00 AM gcc-core-3.4.4.tar.bz2 12846 KB 05/19/2005 10:52:00 AM gcc-g++-3.4.4.tar.bz2 2417 KB 05/19/2005 10:50:00 AM gcc-g77-3.4.4.tar.bz2 882 KB 05/19/2005 10:51:00 AM gcc-java-3.4.4.tar.bz2 4588 KB 05/19/2005 10:51:00 AM gcc-objc-3.4.4.tar.bz2 208 KB 05/19/2005 10:51:00 AM gcc-testsuite-3.4.4.tar.bz2 2575 KB 05/19/2005 10:51:00 AM
Select only which components you wish to install. You will need the gcc-core and any extra language you use (ada, g++, etc.) -OR- download gcc-3.4.4 which will contain ALL of the languages above. ... For this example, I only require gcc-core and gcc-g++.
GCC recommends you do NOT build in the same directory as your source files are. So simply create a separate build directory. To start, I have downloaded and unzipped my selected tar.bz2 file from above into the directory: gcc.
[mirandam@charon gcc]$ pwd /home/mirandam/gcc [mirandam@charon gcc]$ bzip2 -cd gcc-core-3.4.4.tar.bz2 | tar xvf - [mirandam@charon gcc]$ bzip2 -cd gcc-g++-3.4.4.tar.bz2 | tar xvf - -OR (the whole thing)- [mirandam@charon gcc]$ bzip2 -cd gcc-3.4.4.tar.bz2 | tar xvf - [mirandam@charon gcc]$ mkdir build (this is our build directory) [mirandam@charon gcc]$ cd build (important step)
Our build directory above is /home/mirandam/gcc/build/. All our source code for GCC-3.4.4 is located in /home/mirandam/gcc/gcc-3.4.4/.
Extensive options are listed on the GCC configuration page provided on gnu.org. Most importantly the options must be set so as to NOT conflict or interfere with the GCC already installed on Fedora Core installation.
The following options are some recommendations and observations taken from Fedora's configuration of GCC.
[mirandam@charon build]$ pwd /home/mirandam/gcc/build [mirandam@charon build]$ /home/mirandam/gcc/gcc-3.4.4/configure \ --prefix=/opt/gcc34 \ --program-suffix=34 \ --enable-languages=c,c++ \ --enable-shared --enable-threads=posix --disable-checking \ --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
Once done configuring above, you just need to compile and install. Everything has been compiled as a user. Make sure to only use when installing.
[mirandam@charon build]$ make (this compiles, takes 10-30min) [mirandam@charon build]$ su (logs you in as root, to install) Password: [root@charon build]# pwd /home/mirandam/gcc/build [root@charon build]# make install
Now create a text file named: gcc34.sh and in it add the following.
#!/bin/sh GCC34_BIN=/opt/gcc34/bin PATH=$GCC34_BIN:$PATH export PATH
As root, place the file into /etc/profile.d/ and make sure it has execute permissions for all.
[root@charon ~]# ls -la /etc/profile.d/gcc34.sh -rw-r--r-- 1 root root 66 Jun 15 21:38 /etc/profile.d/gcc34.sh [root@charon ~]# chmod 755 /etc/profile.d/gcc34.sh [root@charon ~]# ls -la /etc/profile.d/gcc34.sh -rwxr-xr-x 1 root root 66 Jun 15 21:38 /etc/profile.d/gcc34.sh
You should logout and log back in, or just run a new terminal or xterm and gcc34 should work from any prompt.
If you installed as above, running gcc34 or any other app you installed should be directly accessible. You can verify with the following steps:
[mirandam@charon ~]$ which gcc34 /opt/gcc34/bin/gcc34 [mirandam@charon ~]$ which g++34 /opt/gcc34/bin/g++34 [mirandam@charon ~]$ gcc34 -v Reading specs from /opt/gcc34/lib/gcc/i686-pc-linux-gnu/3.4.4/specs Configured with: /home/mirandam/gcc/gcc-3.4.4/configure --prefix=/opt/gcc34 --program-suffix=34 --enable-languages=c,c++ --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions Thread model: posix gcc version 3.4.4
There are many ways to use an alternate compiler. The 3 methods I commonly use: 1. Environment Variable, 2. Configure Support, and 3. Makefile Support.
Most softwares support the CC and CXX environment variables. First assign them, then run configure and/or make. Example:
# export CC=gcc34 # export CXX=g++34 # ./configure
If the software is using the standard GNU automake and configure, then there is a chance it supports other compilers by passing in a setting to the configure script. First run configure --help to see if it mentions anything. The following example is from MPlayer:
# ./configure --help # ./configure --cc=gcc34
Sometimes the software may just come with a Makefile. Open the Makefile and look inside to see if there are variables that specify the compiler. You can either edit those variables or set them at compile time. For example:
(in Makefile) C_COMPILER = cc CPLUSPLUS_COMPILER = c++
Then using the Makefile, you can run:
# make CPLUSPLUS_COMPILER=g++34
Help Out: If you found this guide or any Resource helpful, please consider supporting this site by recommending this page to others or linking to this page. I appreciate all the support I receive. Thank you in advance.
Disclaimer: The author makes no claim to the accuracy of the information provided. This information is provided in the hope that it will be useful, but WITHOUT ANY WARRANTY. There is no implied support from referencing this guide. Any help that is provided is at will. Use this information at your own risk. Always make proper backups and use caution when modifying critical system files.
PLEASE DO NOT mirror, translate or duplicate this page without contacting me.
Copyright © 2003-2013 by Mauriat Miranda (mjmwired.net).