Using newer gcc in /opt/netapps: Difference between revisions

From LWP-Wiki
Jump to navigation Jump to search
(Add gcc-5.0)
No edit summary
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:software-faq]]
[[Category:software-faq]]
Gcc-4.9.1 is in /opt/netapps/gnu/gcc. In order for you to use it, this may have to be appended to your .profile, .bash_profile or whatever applies.


# This is a bash snippet, to be sourced from .profile
Gcc-5.2 is in /opt/netapps/gnu/gcc/5.2. In order for you to use it, this may have to be appended to your .profile:
 
GCCBASE="/opt/netapps/gnu/gcc"
  GCCSNIPPET=/opt/netapps/gnu/gcc/5.2/sourceme
  [ -r ${GCCSNIPPET} ] && . ${GCCSNIPPET}
# If you want the newer tools by default, put them at the beginning of $PATH
export PATH="${PATH}:${GCCBASE}/bin"
# Have Make pick the newer compiler
  export CXX="${GCCBASE}/bin/g++"
# For good measure: default compiler flags for the C++ course
export CXXFLAGS="${CXXFLAGS} -Wall -std=c++11"
# This is for during compile: prefer newer headers
CPLUS_INCLUDE_PATH="${GCCBASE}/include:${CPLUS_INCLUDE_PATH}"
# This is for linking during build: prefer newer libraries
export LD_LIBRARY_PATH="${GCCBASE}/lib/../lib64:${LD_LIBRARY_PATH}"
   
# This is for runtime linking: prefer older libraries
export LD_RUN_PATH="${LD_RUNPATH}:${GCCBASE}/lib/../lib64"
# Man should also find the newer manpages
export MANPATH="${MANPATH}:${GCCBASE}/share/man"


Please note: /opt is *NOT* in ld.so.conf, and should not be
Please note: /opt is *NOT* in ld.so.conf, and should not be


The environment variables that are set in the sourceme snippet influence Make-like programs (GNU make, icmake). So projects using such utilities will automatically build your programs using the newer compiler.
If you want to build by calling the compiler directly, you cannot just call 'g++'. Instead, call the newer compiler as $CXX, like this:
${CXX} -o hello hello.cc
NB: if you are reading this page as a participant (or attendee) of the C++ course, please ask your questions on the mailing list first, not through the Service Desk.
== Later versions ==
You may find that still later versions are available. Check /opt/netapps/gnu/gcc, and alter the above script by adjusting the line
GCCBASE="/opt/netapps/gnu/gcc/5.2"


There is now Gcc-5.0 as well. You can use the above script, but change
== Addendum ==
Programs built with this newer compiler and these newer libraries use a
newer ABI than the regular compiler/libraries on the LWP.
(See
https://gcc.gnu.org/onlinedocs/libstdc%2B%2B/manual/using_dual_abi.html )


GCCBASE="/opt/netapps/gnu/gcc"
If you run such programs without the environment settings that were set
in the shell snippet, the dynamic linker, at run/load time, will give
you relocation errors. Of course it is undesirable to have to set the
environment depending on which executables are going to run, even if you
can predict that at all.


to
Luckily, we can hardcode the new library paths into the executable
during building:
export LDFLAGS='-Wl,--rpath,/opt/netapps/gnu/gcc/5.2/lib64'


GCCBASE="/opt/netapps/gnu/gcc/5.0"
The weird dual-comma syntax means to tell the compiler (-Wl) to tell the
linker to use option "--rpath /opt/netapps/gnu/gcc/5.2/lib64".


Mind you, gcc-5.0 is still in development stage. It hasn't been released yet.
Such an export command, used just before calling Make, will cause Make
to build an executable that '''will''' run without any special environment
settings, albeit only on the LWP, where the paths mentioned actually exist.

Revision as of 17:25, 12 December 2016


Gcc-5.2 is in /opt/netapps/gnu/gcc/5.2. In order for you to use it, this may have to be appended to your .profile:

GCCSNIPPET=/opt/netapps/gnu/gcc/5.2/sourceme
[ -r ${GCCSNIPPET} ] && . ${GCCSNIPPET}

Please note: /opt is *NOT* in ld.so.conf, and should not be

The environment variables that are set in the sourceme snippet influence Make-like programs (GNU make, icmake). So projects using such utilities will automatically build your programs using the newer compiler.

If you want to build by calling the compiler directly, you cannot just call 'g++'. Instead, call the newer compiler as $CXX, like this:

${CXX} -o hello hello.cc

NB: if you are reading this page as a participant (or attendee) of the C++ course, please ask your questions on the mailing list first, not through the Service Desk.

Later versions

You may find that still later versions are available. Check /opt/netapps/gnu/gcc, and alter the above script by adjusting the line

GCCBASE="/opt/netapps/gnu/gcc/5.2"

Addendum

Programs built with this newer compiler and these newer libraries use a newer ABI than the regular compiler/libraries on the LWP. (See https://gcc.gnu.org/onlinedocs/libstdc%2B%2B/manual/using_dual_abi.html )

If you run such programs without the environment settings that were set in the shell snippet, the dynamic linker, at run/load time, will give you relocation errors. Of course it is undesirable to have to set the environment depending on which executables are going to run, even if you can predict that at all.

Luckily, we can hardcode the new library paths into the executable during building:

export LDFLAGS='-Wl,--rpath,/opt/netapps/gnu/gcc/5.2/lib64'

The weird dual-comma syntax means to tell the compiler (-Wl) to tell the linker to use option "--rpath /opt/netapps/gnu/gcc/5.2/lib64".

Such an export command, used just before calling Make, will cause Make to build an executable that will run without any special environment settings, albeit only on the LWP, where the paths mentioned actually exist.