Installing Alternate GCC Compiler on Fedora

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:

Make sure you understand all of these steps completely. This is NOT meant for everyone. Please be advised there MAY BE errors. Comments and/or suggestions appreciated.

Problem

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.3 in FC10) 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.


Having Multiple Compilers

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 FC10 and FC11 shipped with a GCC4.x as well as GCC3.2).

Linux is convenient that you can have as many compilers as you like.


Required Software

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 fc11) this includes: Development Tools in the fc11 Install Process -OR- you can go to: System Settings > Add/Remove Applications > Development > Development Tools. The following is an example on fc11:


[root@SWII jackie]$ rpm -q gcc
gcc-4.4.1-2.fc11.i586

Required Files

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 4.3.3 is available. Try to find a mirror with the full files NOT the diff files. The following is only an example:


gcc-4.3.3.tar.bz2  		26920 KB  	05/19/2005  	10:50:00 AM

gcc-ada-4.3.3.tar.bz2	 	3380 KB 	05/19/2005 	10:50:00 AM
gcc-core-4.3.3.tar.bz2 		12846 KB 	05/19/2005 	10:52:00 AM
gcc-g++-4.3.3.tar.bz2 		2417 KB 	05/19/2005 	10:50:00 AM
gcc-g77-4.3.3.tar.bz2 		882 KB 		05/19/2005 	10:51:00 AM
gcc-java-4.3.3.tar.bz2 		4588 KB 	05/19/2005 	10:51:00 AM
gcc-objc-4.3.3.tar.bz2	 	208 KB 		05/19/2005 	10:51:00 AM
gcc-testsuite-4.3.3.tar.bz2 	2575 KB 	05/19/2005 	10:51:00 AM

gmp-4.2.4.tar.bz2 		1711 KB 	09/20/2008 	06:16:00 AM
mpfr-2.3.2.tar.bz2 		963 KB 		09/12/2008 	10:00:00 PM

 

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-4.3.3 which will contain ALL of the languages above. ... For this example, I only require gcc-core and gcc-g++.


Setting Up Sources and Directories

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.


[root@SWII jackie]$ pwd
/home/jackie/gcc

[root@SWII jackie]$ bzip2 -cd gcc-core-4.3.3.tar.bz2 | tar xvf -
[root@SWII jackie]$ bzip2 -cd gcc-g++-4.3.3.tar.bz2 | tar xvf -

-OR (the whole thing)-
[root@SWII jackie]$ bzip2 -cd gcc-4.3.3.tar.bz2 | tar xvf -

[root@SWII jackie]$ wget -c http://www.mpfr.org/mpfr-2.3.2/mpfr-2.3.2.tar.bz2; wget -c http://ftp.ntu.edu.tw/gnu/gnu/gmp/gmp-4.2.4.tar.bz2
[root@SWII jackie]$ tar jxvf mpfr-2.3.2.tar.bz2; mv mpfr-2.3.2 gcc-4.3.3/mpfr; tar jxvf gmp-4.2.4.tar.bz2; mv gmp-4.2.4 gcc-4.3.3/gmp
[root@SWII jackie]$ mkdir build (this is our build directory) [root@SWII jackie]$ cd build (important step)


Our build directory above is /home/jackie/gcc/build/. All our source code for GCC-4.3.3 is located in /home/jackie/gcc/gcc-4.3.3/.


Configuring Options

Extensive options are listed on the GCC configuration page provided on gnu.orgMost 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.


  • prefix is used to set where GCC will be installed. This is typically /usr/local, but I want to keep it completely separate in /opt/gcc43. If I ever plan to remove it, I will simply remove the directory. The compiled gcc,g++,etc. will be in /opt/gcc43/bin/.
  • program-suffix is used to attach an extra character or string to every GCC application that gets compiled. I have used 34. So my compiler will be gcc43,g++43, etc. This is done so I avoid any confusion with the existing GCC installed (or even GCC 3.2 in fc11). You can also use program-prefix instead (ex:mygcc).
  • enable-languages allows you to control which compilers you want built. If you select all (c,c++,objc,java,f95,ada) make sure you either have all the language added or you used the full gcc tag.bz2 package. (I only care for c and c++.)
  • The last set of options (in italics) are meant entirely for compatibility with Fedora.


[root@SWII build]$ pwd
/home/jackie/gcc/build

[root@SWII build]$ /home/jackie/gcc/gcc-4.3.3/configure \
	--prefix=/opt/gcc43 \
	--program-suffix=34 \
	--enable-languages=c,c++ \
	--enable-shared --enable-threads=posix --disable-checking \
	--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions

Compile and Install

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.


[root@SWII build]$ make             (this compiles, takes 10-30min)

[root@SWII build]$ su               (logs you in as root, to install)
Password: 

[root@SWII build]# pwd
/home/jackie/gcc/build

[root@SWII build]# make install


Now create a text file named: gcc43.sh and in it add the following.


#!/bin/sh
gcc43_BIN=/opt/gcc43/bin
PATH=$gcc43_BIN:$PATH
export PATH


As root, place the file into /etc/profile.d/ and make sure it has execute permissions for all.


[root@SWII ~]# ls -la /etc/profile.d/gcc43.sh 
-rw-r--r--  1 root root 66 Jun 15 21:38 /etc/profile.d/gcc43.sh

[root@SWII ~]# chmod 755 /etc/profile.d/gcc43.sh

[root@SWII ~]# ls -la /etc/profile.d/gcc43.sh
-rwxr-xr-x  1 root root 66 Jun 15 21:38 /etc/profile.d/gcc43.sh


You should logout and log back in, or just run a new terminal or xterm and gcc43 should work from any prompt.


Using New GCC

If you installed as above, running gcc43 or any other app you installed should be directly accessible. You can verify with the following steps:


[root@SWII ~]$ which gcc43
/opt/gcc43/bin/gcc43
[root@SWII ~]$ which g++43
/opt/gcc43/bin/g++43

[root@SWII ~]$ gcc43 -v
Reading specs from /opt/gcc43/lib/gcc/i686-pc-linux-gnu/4.3.3/specs
Configured with: /home/jackie/gcc/gcc-4.3.3/configure --prefix=/opt/gcc43
--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 4.3.3


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.



Environment Variables


Most softwares support the CC and CXX environment variables. First assign them, then run configure and/or make. Example:


# export CC=gcc43
# export CXX=g++43
# ./configure



Configure Support


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 configurescript. First run configure --help to see if it mentions anything. The following example is from MPlayer:


# ./configure --help
# ./configure --cc=gcc43



Makefile Support


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++43

More information:


 

arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()