10

i just installed gcc 4.9 using the link here and it is a very good link. But I have only one problem which i dont want to try not to mess up --> linking the libraries and path variables.

we have a cluster in our college and i installed this in my home directory (without root). Now my home/ directory contains this folder where all the gcc folders are :

bin  
include  
lib  
lib64  
libexec  
share

What all do i have to do to point to the g++/gcc binary in bin folder with additional linking ? For example, set ld_library_path, set binary paths (export PATH = /home/asdf/gcc4.9/bin:$PATH) . etc..

Can anyone provide details on what all needs to be done to use gcc/g++ 4.9 (installed by me) by bypassing the older version of gcc installed by root.

Do i have to add lib and lib64 to the ld_library_paths as well ? Will i have to use " " instead of < > to include files (e.g. # inlcude "set" or #include and it includes from gcc4.9 and not the old one ) Or explicitly provide the include path using -I

Any suggestions/discussions/comments are welcome. I am aware this may marked as duplicate, but it will really be useful to all the people out there who want to try the new gcc-4.9 with c++11 without messing up the environment variables.

PS: I am not asking how to export or set an environment variable. I am asking what all environment variables are required to use my non-root version of gcc and not the root's older version and not mess up the ld paths and so paths during runtime.

thanks !!

Community
  • 1
  • 1
pugs
  • 155
  • 1
  • 8

1 Answers1

8

If you build your compiler with --prefix=/home/myname/gcc4.9 (adjust to match your system, obviously), then the compiler should "know" that the include paths etc.

All you need beyond that is to make sure your path has /home/myname/gcc4.9/bin before /usr/bin or wherever your other gcc is installed, and everything should work just like normal. On my machine, I have gcc 4.8.2 installed from my own build and gcc 4.6.3 from the linux installer for gcc (because it's a fairly old distro). And as long as I have the paths set in the right order, it works "automagically".

You will need to set LD_LIBRARY_PATH, but include-paths and static libraries should be handled by gcc itself.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • @ Mats : yes, i did build my compiler with the above prefix you mentioned. So all i have to do is set ld_library_path = /home/myname/gcc4.9/lib and /home/myname/gcc4.9/lib64 ... and path for bin folder as /home/myname/gcc4.9/bin .. and that will be all right ? Just one last query, how do I override /usr/bin (root installed gcc) Our cluster has modules system through which gcc is loaded, so instead, (1) not to load the module and (2) just put the above paths in .bashrc and source it... – pugs May 17 '14 at 13:46
  • Yes, "don't load the module" and make sure your path starts with your local gcc location, before /usr/bin (in other words `export PATH=/home/myname/gcc/bin:${PATH}`, and similarly for the `LD_LIBRARY_PATH`. – Mats Petersson May 17 '14 at 21:57