Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Multiple switchable gcc version
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
F1r31c3r
Tux's lil' helper
Tux's lil' helper


Joined: 31 Aug 2007
Posts: 78
Location: UK

PostPosted: Sun Jan 09, 2011 1:40 pm    Post subject: Multiple switchable gcc version Reply with quote

I was having problems finding info on how to install and switch between multiple installed GCC version.

Some old programs require GCC-3 to compile and as we all know at the moment we use GCC-4.4.4 so my compile failed.

Instead of recoding the qemu project which i needed to compile i installed GCC-3.4.6-r2 and then found a handy method of switching between compilers quickly.

I thought i would share it as a tip and trick.

Note here if you use CFLAGS="-O2 -march=native" in your /etc/make.conf you will need to change thhis. I made a second line temporarily commenting out the #CFLAGS="-O2 -march=native" with the sharp sign then i added CFLAGS="-O2 -march=pentium4" This is because GCC-3 does not have the feature to automatically detect your CPU features. This is one of the great benefits of GCC-4 but hey. After you are done and switch back to GCC-4 just edit your /etc/make.conf and swap the sharp sign# to comment in native and comment out the pentium4 and your all good.

First of lets unmask GCC versions this gives us access to install masked versions. Note you may not need do this step so i suggest first try it without unmasking with keywords and just jump to the next step. If its masked or not found then do the unmasking.

Quote:
# echo "sys-devel/gcc ~x86" >> /etc/portage/package.keywords


Next we need to verify its being installed in a new slot (NS)

Quote:
# emerge -av =sys-devel/gcc-3.4.6-r2


It should say in [ NS ] if it does your good to go so say yes. Of course this is for version 3.4.6-r6 if you want a different version adjust accordingly. The = sign is crucial for those that dont know.

After this has completed the magic switching and listing commands are as follows:

To switch to the 3.4.6 do this
Quote:


# gcc-config i686-pc-linux-gnu-3.4.6


To List the available versions you have installed and can switch to(its an lower cap L):
Quote:



# gcc-config -l


To switch back to version 4.4.4 or whichever higher version you have installed(use list command above to list which they are)

Quote:


# gcc-config i686-pc-linux-gnu-4.4.4




Thats it, this is how you can have multiple versions of GCC installed and switch between them as and when needed. I understand it is very rare in many cases to do this probably 1 out of 2000 possible packages this maybe handy. Again due to the serious lack of information on this out there across the web i felt a need to make sure it was documented.

I am sure and hope it would help someone.
_________________
When i look In-between white and black i see a rainbow of colours
Back to top
View user's profile Send private message
casualx
n00b
n00b


Joined: 06 Feb 2012
Posts: 49
Location: rohrbach,switzerland

PostPosted: Thu Mar 22, 2012 2:00 am    Post subject: Reply with quote

yes this helps me really!
thx a lot
Back to top
View user's profile Send private message
gringo
Advocate
Advocate


Joined: 27 Apr 2003
Posts: 3707

PostPosted: Fri Mar 23, 2012 11:06 am    Post subject: Reply with quote

no need to write the hole toolchain name, there is a number at the beginning of each line so that all you actually have to do is : gcc-config 1 ( or whatever).

cheers
Back to top
View user's profile Send private message
big_gie
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 158

PostPosted: Sat Apr 21, 2012 7:05 pm    Post subject: Reply with quote

Is gcc-config change possible on a per-user basis? Or is a system wide change which requires root?

Having the possibility to change it user-wise would be interesting. For example, I would love to use the stable gcc version installed on my machine, say 4.5, but have a 4.6 or 4.7 installation around to have access to its newer features for my own programs (not for any system-wide installation).

Basically, a gcc installed version used only for non-protage programs.

Is that possible?
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1639

PostPosted: Sat Apr 21, 2012 7:51 pm    Post subject: Reply with quote

Unfortunately, no.

But you can always specify your compiler (e.g. "gcc-4.6" instead of just "gcc"). And if that's too much trouble, you can create a directory with symlinks that point to the right versions and add it to PATH to override the system version.
_________________
“And even in authoritarian countries, information networks are helping people discover new facts and making governments more accountable.”– Hillary Clinton, Jan. 21, 2010
Back to top
View user's profile Send private message
big_gie
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 158

PostPosted: Sat Apr 21, 2012 7:54 pm    Post subject: Reply with quote

Hum ok. So I guess I could install the updated compiler and write an eselect module which would set a different gcc version for a user...
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1639

PostPosted: Sat Apr 21, 2012 7:55 pm    Post subject: Reply with quote

If you do, please share! :)
_________________
“And even in authoritarian countries, information networks are helping people discover new facts and making governments more accountable.”– Hillary Clinton, Jan. 21, 2010
Back to top
View user's profile Send private message
big_gie
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 158

PostPosted: Sat Apr 21, 2012 7:56 pm    Post subject: Reply with quote

Of course ;)
It would show up on my github: https://github.com/nbigaouette/ebuilds/
(and my layman repo: nbigaouette)
Back to top
View user's profile Send private message
big_gie
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 158

PostPosted: Fri Jun 01, 2012 6:01 pm    Post subject: Reply with quote

I finally took on to do this.

It seems there was previously an eselect module named "eselect-compiler" but which was dropped due to problems with it. I've checked also if I could modify gcc-config to take a flag to work locally and not system wide, but there seems to be many hardcoded path in it.

So I decided to write from scratch an eselect module as I think it the best/simplest approach. It's relatively simple. It will modify the PATH variable by removing the one for gcc and placing the one for the wanted version at the front. It can be enabled/disabled easily and per-user (does not set anything system-wide).

Even if nothing is set by the user, it will show the global version as active (as reported by gcc-config -c).

I called it "gcc-user", but it just was the first name that came to mind.

Feel free to comment!

https://github.com/nbigaouette/eselect-gcc-user
Back to top
View user's profile Send private message
mixsms
n00b
n00b


Joined: 06 Jul 2012
Posts: 1

PostPosted: Fri Jul 06, 2012 1:24 pm    Post subject: Reply with quote

Its really helpful for me and ofcourse for all. Thx for sharing.
Back to top
View user's profile Send private message
EatMeerkats
Apprentice
Apprentice


Joined: 15 Mar 2006
Posts: 234

PostPosted: Fri Jul 06, 2012 2:01 pm    Post subject: Reply with quote

An easier way to manage compiler versions for different packages is using portage's package.env: http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?part=3&chap=6#doc_chap2
Back to top
View user's profile Send private message
cerddwr
n00b
n00b


Joined: 28 Nov 2004
Posts: 61
Location: Birmingham, UK

PostPosted: Wed Jul 18, 2012 9:25 am    Post subject: Reply with quote

This has been helpful to me as well. Trying to upgrade libreoffice, emerge failed with the message "gcc version too old, gcc-4.5 needed" or similar.
As I had already installed gcc-4.5.3 I could not understand it. This simple trick solved the problem. :D
_________________
"The Internet is not a literacy-free-zone"
Back to top
View user's profile Send private message
big_gie
Apprentice
Apprentice


Joined: 31 Aug 2004
Posts: 158

PostPosted: Wed Jul 18, 2012 2:15 pm    Post subject: Reply with quote

Yes, package.env is useful for compiling some packages using a different compiler. I've been using this to compile some packages using Intel ICC.

But I couldn't find something that allows a user (without root access) to use a different compiler (without manually setting some environment variables). I need this not to compile portage packages, but to compile my own code. GCC 4.7 is a lot faster to compile and we hope to get a faster binary with it too. Diagnostics are also improving in GCC so using the latest version for your own code does make sense. But I don't want portage to use it as it is not marked stable yet and many packages can't be compiled with 4.7...
Back to top
View user's profile Send private message
megabaks
Apprentice
Apprentice


Joined: 22 Jan 2012
Posts: 237
Location: Russia && Saint-Petersburg

PostPosted: Sun Sep 16, 2012 11:08 pm    Post subject: Reply with quote

gcc-config? noway!
per_package_switcher( in /etc/portage/bashrc)
Code:
#COMPILERS
if [ -f ${ROOT}/etc/portage/package.compilers ]; then
  while read target ver; do
   if [ "${target}" = "${CATEGORY}/${PN}" ]; then
    MY_GCC="$(find /usr/$MACHTYPE/gcc-bin/ -name "$ver*")"
    export ROOTPATH="${MY_GCC}:${ROOTPATH}"
    export PATH="${MY_GCC}:${PATH}"
    export LIBRARY_PATH="$(gcc-config -L):${LIBRARY_PATH}"
   fi
  done < ${ROOT}/etc/portage/package.compilers
fi

#COMPILERS_FULL
if [ -f ${ROOT}/etc/portage/package.compilers-full ]; then
  while read target ver; do
   if [ "${target}" = "${CATEGORY}/${PN}" ]; then
    MY_GCC="$(find /usr/$MACHTYPE/gcc-bin/ -name "$ver*")"
    export ROOTPATH="${MY_GCC}:${ROOTPATH}"
    export PATH="${MY_GCC}:${PATH}"
    export LIBRARY_PATH="${MY_GCC}:${LIBRARY_PATH}"
   fi
  done < ${ROOT}/etc/portage/package.compilers-full
fi
in /etc/portage/package.compilers{-full} put as example "sys-boot/grub 4.4" ---> grub will compiled with 4.4 gcc
different between compilers and compilers-full:
compilers switch only gcc version, but use libs by current system gcc
compilers-full switch and gcc and libs to target version
Back to top
View user's profile Send private message
diablo465
Tux's lil' helper
Tux's lil' helper


Joined: 10 Sep 2013
Posts: 92

PostPosted: Mon Feb 17, 2014 2:49 pm    Post subject: Reply with quote

mark here.
Back to top
View user's profile Send private message
megabaks
Apprentice
Apprentice


Joined: 22 Jan 2012
Posts: 237
Location: Russia && Saint-Petersburg

PostPosted: Sun Mar 02, 2014 3:11 pm    Post subject: Reply with quote

Quote:
Great post, i love it. Thank !
actual code ---> https://raw.github.com/megabaks/gcc-switcher/master/gcc-switcher
added messages
added wildcards support
_________________
sorry my bad english
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum