LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-19-2007, 03:15 PM   #1
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Rep: Reputation: 15
Having multiple versions of GCC


A lot of time I read in some packages that they need to be compiled with some version of GCC, MAKE, etc. How does somebody keep multiple versions of GCC, MAKE and so on its computer? What has to be done when changing GCC version? Making new symbolic links to /bin folder that points to different GCC version? Not to mention all other tools like linker, archiver, nm, readelf, etc. Is there some easy way to do this?

That goes the same for using different version of libstdc++, etc. What is the easiest way of keeping multiple versions of some library on the computer and easily changing between them.

As a developer I'm coming from windows world so I'm having a lot of difficulties with this stuff.

Best regards,
 
Old 11-19-2007, 08:07 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
Both Fedora and Ubuntu package multiple gcc's for you. Just install the packages with either yum or synaptic. They will install one gcc as gcc3.4 and one as gcc4.1. Then its up to the distro which is symlinked to 'gcc'. 3.4 and 4.1 are the two versions you'll really need.

And you won't need to fuss about with manually symlinking anything. You just set the environment variable CC to whichever you want to use. From a terminal, that may look like
Code:
CC='gcc4.1'
Then most sane packages will use that as their C compiler.

Regarding linkers, archivers and the lot: you just keep one version. One set of binutils can serve all your various compilers. Software isn't fussy about what binutils is used, so no need for concurrent versions there.

And libraries - package manager again. It handles most all of the details of keeping them separate. If you needed two versions of a library as a developer, you would know it and you would know how to handle it. It varies on a case-by-case basis, but if you aren't sure if you need different versions, you don't. You mention libstdc++, you are aware that, like binutils, one can serve multiple compilers? Now if you wish to test differing implementations of libstdc++ that's a different story, but if you just want multiple compilers there's no need for multiple libstdc++.
 
Old 11-20-2007, 06:13 AM   #3
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 15
I didn't know that it doesn't matter which binutils you use. So it doesn't matter what is the version of nm or ld linker? What about archives and libraries that were cross compiled? They can be linked with any linker? They can be read with any elfread?

Doesn't libstdc++ come with C++ compiler? It doesn't have to be the same version?

Regards,
 
Old 11-20-2007, 01:13 PM   #4
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
Well, you mentioned cross compiling here - remember that cross compiling is a whole different beast. If you are always compiling for the same architecture, then the binutils are fine, but I've never (sucessfully) cross-compiled, so I don't know if there are any issues there. I'm unsure if the libstdc++ is bundled with the compiler, it's been a while since I installed one, but if it is bundled then package management will handle all that for you anyways.

So cross compiling is compiling a package for a MIPS processor on my x86 machine, not compiling one package with gcc 3.4 and one with gcc 4.1. If you want to do the first, that's a fair bit harder. If you want to do the second, it's a breeze.
 
Old 11-21-2007, 01:10 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,749

Rep: Reputation: 461Reputation: 461Reputation: 461Reputation: 461Reputation: 461
I keep up to five different compiler on my machine. The best way to handle it is to configure and install each one into its' own subdirectory of (usually) /usr, /opt or /usr/local. Then create a wrapper for each one which sets up the path to that compiler and LD_LIBRARY_PATh to those libs. This is more dependable than using binaries with a prefix or suffix on the name,
You can have a look at how I do it by looking at my build script for gcc-3.4.6 here:

http://distro.ibiblio.org/pub/linux/...vel/gcc-3.4.6/

The wrapper is the GCC346 file which gets placed into the normal path and made executable.
To use the compiler you just call the wrapper with whatever commands:
GCC346 make.
I have alos used this method for keeping multiple versions of automake. The eaxmple gcc346 above also has a version of cmake setup to use that compiler.
You don't always need to set the LD_LIBRARY_PATH (for C programs), but for C++ progs you may need to -depending on which version. But the libstdc++ libs should be installed in the normal locations for the binary programs that need them.
I have gcc-2.95.3, 3.2.3, 3.3.6, 3.4.6, 4.1.2, mingw32-gcc-3.4.5 all at once.
Having a separate version of binutils is usually not necessary, unles you are compiling binaries which are not binary-compatible with what's running on your system.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
include path for multiple versions of gcc hydrogeek Linux - General 5 11-18-2007 02:08 PM
Multiple versions of GCC Denisius Slackware 11 11-15-2007 07:39 AM
gcc versions compatibility with kernel versions.. mahesh_manthapuri Suse/Novell 1 03-22-2006 12:28 AM
multiple versions of gcc Avatar33 Linux - General 3 02-22-2005 02:06 PM
multiple gcc versions and selectability tincat2 Linux - Software 1 06-08-2003 02:38 AM


All times are GMT -5. The time now is 03:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration