Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc
This page is a candidate for deletion 
Reason given: Long out of date.
If you disagree with its deletion, please explain why on its discussion page.
If you intend to fix it, please remove this notice, but do not remove this notice from articles that you have created yourself.
Make sure no other pages link here and check the page's history before deleting.
GNU Compiler Collection
Developer: the GNU foundation
Package: sys-devel/GCC
Category: sys-devel
License: GPL-2



GCC: the compiler used on pretty much every *nix and *BSD based system in the world, is one of your system's most basic components, allowing you to compile and install new programs from source.

Most Gentoo systems use the tried-and-true, stable GCC 3.3.x compiler. You can stick with it if you want, but then I doubt you'd be reading this ;). For those who can't wait for 3.4 to get stable, this tutorial details how to update it.

Note: This HOWTO is outdated. GCC 3.4 was marked stable on x86 on December 2, 2005.
Use Gentoo Linux GCC Upgrade Guide

Note: Comment 12/1/2006 - Had some major problems while updating profile from 2005.0 to 2005.1. The script based solutions are posted on side 5 of "C compiler cannot create executables" !??! and everything is according to the HOWTO linked above.

Update the Profile

Note: the following steps can be ignored if you have already installed Gentoo 2005.1 or previously switched to the new profile.

First, let's update your current profile to the latest version which is completely compatible with GCC 3.4. The following example are based on x86 architectures, adjust them accordingly to your system if you are not running x86:

# cd /etc
# mv make.profile make.profile.old
# ln -sf ../usr/portage/profiles/default-linux/x86/2005.1 make.profile

Check your CFLAGS

The CFLAG -mcpu= has been deprecated in GCC 3.4. Use -mtune= or, preferably, -march= instead. Also, don't use agressive CFLAGS (and LDFLAGS for that matter) like -funroll-loops and -ffast-math, etc. Over-optimizing often results in slower binaries (not to mention much greater compilation times). Just stick with -march=, -pipe, and any other safe CFLAGS - just don't use too many and the too exotic, for your own sake.

Unmask GCC 3.4

This section, except the syncing of the portage tree, is no longer necessary if you have x86 architecture like most people

We need to take a couple of steps now to let portage install GCC 3.4. First of all, sync your portage tree to get the latest ebuild for GCC:

# emerge --sync

Depending on your architecture, 3.4 GCC version can be marked as testing or stable.
a) if your architecture is one for which there is a stable version of GCC 3.4, you can skip this section;
b) if not, go on reading this section;
c) if you don't know, please read

Now we need to create a package.keywords file if it does not exist already:

# mkdir /etc/portage
# nano /etc/portage/package.keywords

Now add the following packages to package.keywords using the following commands: (replace ARCH with your architecture, examples: x86, ppc,...)

# echo "sys-devel/gcc-config ~ARCH" >> /etc/portage/package.keywords
# echo "sys-devel/gcc ~ARCH" >> /etc/portage/package.keywords
# echo "sys-libs/glibc ~ARCH" >> /etc/portage/package.keywords
# echo "sys-libs/libstdc++-v3 ~ARCH" >> /etc/portage/package.keywords

To verify the previous steps were correctly implemented:

# emerge -pv gcc

You will be greeted with the following output (if glibc 2.3.x is already present on your system it will not appear in the list.):

[ebuild N ] sys-libs/glibc-2.3.x
[ebuild N ] sys-libs/libstdc++-v3
[ebuild NS ] sys-devel/gcc-3.4.x

Emerge GCC 3.4

NOTE: All examples are for the x86 architecture. If you are running AMD64 or another type of architecture, your outputs will vary accordingly.

Emerge GCC 3.4:

# emerge -v gcc

Now go grab a pizza, because building gcc takes forever ;P

Before changing the current profile to point to the new GCC 3.4, first run:

# gcc-config -l

You will be greeted by a similar output:

[1] i386-pc-linux-gnu-3.3.4 *
[2] i686-pc-linux-gnu-3.4.3 
[3] i686-pc-linux-gnu-3.4.3-hardened
[4] i686-pc-linux-gnu-3.4.3-hardenednopie
[5] i686-pc-linux-gnu-3.4.3-hardenednossp

The current profile is indicated by the *. Use the following command to change profiles to the new GCC 3.4. You can also give the number of the profile instead of the name.

# gcc-config i686-pc-linux-gnu-3.4.3
# source /etc/profile

NOTE: The last version number may vary depending on future versions of GCC.

Verify you have indeed changed profiles correctly:

# gcc-config -l

You will be greeted with a similar output:

[1] i386-pc-linux-gnu-3.3.4 
[2] i686-pc-linux-gnu-3.4.3 *
[3] i686-pc-linux-gnu-3.4.3-hardened
[4] i686-pc-linux-gnu-3.4.3-hardenednopie
[5] i686-pc-linux-gnu-3.4.3-hardenednossp

After completing this step, you will see a message about continuing work in the same shell. Be sure to update your Gentoo profile before continuing, or else the previous version of GCC will still be called. You can check the current version being used with:

# gcc -v

If the version being reported is your older GCC installation, updating your Gentoo system profile will properly set the system to use GCC 3.4:

# source /etc/profile

As soon as you have changed profiles, please continue to the next step of the guide.

Re-emerge your System & World Packages

It is now adviseable to run the following commands to at least re-emerge the contents of system:

# emerge -e system 

If you want to have all of your new packages compiled with the new 3.4 compiler, then use the below command. Note however that this command results in quite a time-consuming compilation, especially if you've got a lot of programs on your system; but, it will ensure all of your programs use the more optimized (hopefully ;) code produced by the new gcc. If you want to go this route, you may as well leave the computer running overnight (and depending on your machine, over the weekend!).

# emerge -e system && emerge -e world

Again, at a bare minimum re-emerge your system packages (first command) which includes the very-important glibc, one of the libraries essential to your compiler. You could, if you wish, use the second command, but that's unnecessary; as you update packages the newer compiler will be used.

Removing gcc-3.3.x

You'll probably find that an emerge world will try and upgrade your gcc-3.3.x install even when you're running on 3.4.x. To stop this from happening you can remove gcc-3.3.x from your system.

DO NOT do this until you have tested your system with gcc 3.4.x as the following procedures disables the ability to revert back to 3.3.x.

REMEMBER this is a dangerous step and can result in an impaired system (in the case of missing libstdc++ on depclean). This step must be done after the previous ones.

If unfortunately, you have removed gcc-3.3.x without re-emerging system, you'll perhaps get an error: " can not be found". At this moment, you can get the file from original gentoo installation CD (unpack it from the package, be sure the gcc version is the same) and copy it to /usr/lib/, then you can go back to the previous step to re-emerge system.

N.B. Before doing this you should check that none of your packages have gcc-3.3.x as a dependency by running:

# emerge -pv --update --deep world --tree

Remove gcc-3.3.x from your system.

# emerge -C =gcc-3.3.<version>

You can find your <version> by typing

# gcc-config -l

and subsituting <version> for your entire build number - eg) =gcc-

After the unmerge you may need to repair some libraries do this using revdep-rebuild (may take some time)

# revdep-rebuild

note: some binary packages require the old libstdc++ library, these packages can be repaired by emerging libstdc++-v3 so if you get problems with missing libstdc++ usually related to realplay

# emerge libstdc++-v3



GCC is a slotted package, meaning you can have more than one gcc version installed on your machine. In this case, if your upgrade failed or you have come into problems, you can simply revert back to your old GCC version by reversing the method used to change your profile to the new version.

If the compilation phase fails due to a particular package, please try this command (substitute 3.3.4 with your old gcc version):

# 3.3.4 

Also, if you went from i386 to i686, this would also be helpful:

# 3.3.4 --oldarch i386-pc-linux-gnu

If even this fails, then take note of the problematic package and resume the compilation with this command:

# emerge --resume --skipfirst

Kernel and External Drivers

It might also be a smart thing to rebuild your kernel. Mostly in case you update external drivers, since after updating those can't be loaded anymore.

(Don't forget to back-up and restore your kernelconfig. Also, make clean deletes all kernel modules, so if your boot partition file system is compiled as a module, mount boot partition before starting this step)

File: Kernel 2.6.x
# cd /usr/src/linux && make clean
# make && make modules_install
# update-modules
# cp /usr/src/linux/arch/i386/boot/bzImage /boot/[your kernelfile here]

Now rebuild your external drivers as described in Kernel/Upgrading. If you don't do this the module(s) will not load at boot-time and report an error "invalid module format" if you try modprobing it later.


If you use Ccache compiler cacher - don't forget to run "ccache -C" to clear the current cache. Since all of your previous cache'd compiles were done using the old GCC, none of the contents of the old cache apply. Failure to do so will result in lots of compilation failures.

Retrieved from ""

Last modified: Sun, 24 Aug 2008 20:40:00 +0000 Hits: 79,405