Reputation: 5387
I have a computer at work, on which I don't have sudo privileges (it is managed by a sysadmin), and I only have write permissions in /home/my_user_name/
We use Scientific Linux release 6.3 with gcc version 4.4.7. I want to compile my own gcc 4.9.1, install it in, say, /home/my_user_name/local/gcc/
, and be able to use it concurrently with the old gcc 4.4.7.
I understand that by default, g++ will check under /usr/
and /usr/local/
for headers and libraries before looking into user specified directories. Also, executables check default paths for shared objects at runtime.
What I want, is for gcc-4.4.7 to use its own headers, libraries, linker, etc., and for gcc-4.9.1 to use it's own suite, without seeing older versions of those things in /usr/
and such. And for executables, to automatically know where to look for libraries which they were compiled with. I'd also like for both compilers to be available at the same time. I'd also like for this to apply to gfortran and other compilers included in gcc.
Can this be done? What is the best way to set this up? What do I need to know or worry about?
Thanks
Upvotes: 2
Views: 3706
Reputation: 5731
Can this be done? What is the best way to set this up? What do I need to know or worry about?
Yes, this can be done. In fact it is very comman to have multiple version of GCC in one machine.You download and install gcc4.9 in your path /home/my_user_name/local/gcc/
. You can refer the following link about how to install GCC4.9 using source file.
How do I compile and run GCC 4.9.0?
Once you are done with the steps, you should be able to use GCC4.9.1 by providing the complete path. The best way could be to write a makefile and use it to avoid long type.
If everything goes fine with your GCC4.9 installation, following command should give the output like this:
$/home/mantosh/gcc-4.9.1/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/mantosh/gcc-4.9.1/bin/gcc
COLLECT_LTO_WRAPPER=/home/mantosh/gcc-4.9.1/libexec/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/mantosh/objdir/../gcc-4.9.1/configure --prefix=/home/mantosh/gcc-4.9.1 --disable-multilib
Thread model: posix
gcc version 4.9.1 (GCC)
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.1-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)
So from above, we can see that GCC4.8 is my default compiler and GCC4.9.1 is other compiler installed. The first one would be compiled by default gcc(which gcc4.8 in my case) and in second case by gcc4.9.1. as we are giving complete path on command line.
$g++ test.cpp
$/home/mantosh/gcc4.9.1/bin/g++ test.cpp
Upvotes: 2