This post describes a way of building and installing additional versions of GNU gcc compiler on Fedora 15.
The version shipped with Lovelock is gcc 4.6.1 which, surprisingly, can sometimes be too new. Some apps such as nVidia CUDA SDK requires a specific version of compiler for some reason. In this howto I’ll be installing gcc-4.4.6.
Notice: There is an official installation guide that will help you if something doesn’t work (or I forgot to mention something here).
1. Getting the Source
I guess, nobody will be surprised when I say, that the first step is to obtain
the sources. Go to http://gcc.gnu.com, pick
a mirror and download the version you need. The best option is usually
downloading the package with all languages included (e.g.
We will unpack the archive and rename the directory to
source/ . It is also
recommended to build the binaries into a separate directory from the sources,
so we’ll create a
build/ folder too:
Now we have everything in place, we need to configure the build. Change into
build/ directory and call the configure script:
As you can see, there are some parameters.
--prefix option says where should
be the gcc installed after the build. We will install it separately into the
/opt directory, so it will be easily removable in the future only by deleting
the respective directory.
--program-suffix will be added to the name of the
executable (in this case
gcc-4.4 ), so it doesn’t collide with other
installed versions of gcc on your system.
Warning: Be careful with the
--program-suffix option. You might have to make
some symlinks to use the compiler in some vendor Makefiles. It will be
explained later in this post.
Optionally you can add
--enable-languages=c,c++ to choose what languages
support will be compiled. For more options, refer to the official guide above.
In case the configure script fails, you probably don’t have all the necessary packages installed to perform the build. See what’s missing and install it with yum. For me the following was enough:
The full list of prerequisites can be found here.
The build is fairly simple, if you see some warnings, feel free to ignore
them. To build gcc write the following inside the
Now is the time to get some coffee, because it will take a while to build.
Installation is also quite easy. You can install gcc by writing
Then check whether the installation was correct and everything is in place
5. Using the alternative compiler
Using the alternate compiler is a little tricky. You can it to your system
path by appending this line to your
The alternate compiler is available through gcc-4.4 name (as we defined in
the configuration phase). That is cool for your Makefiles, but some vendors
hardcode compiler name into their Makefile which doesn’t help at all. If this
is your case, the best way to get things to work is to make symlinks to the
alternate gcc and append the directory to the begining of
Here are example symlinks for gcc and g++:
Note, that the system look-up in the
$PATH folder is sequential, so if you
append the directory to the front of the variable, it will have higher
priority. If you need to use the newer compiler again, simply remove the
directory from path by commenting out the line in
~/.bashrc . Remember, you
can always find out version of your current gcc by writing