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.
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
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++.
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?
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.
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:
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:
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.
|All times are GMT -5. The time now is 09:49 AM.|