* multiple installed versions of gcc -- automatically set rpath ?? @ 2020-05-29 2:54 Patrick Herbst 2020-05-29 3:07 ` Dan Kegel 2020-05-29 11:33 ` Jonathan Wakely 0 siblings, 2 replies; 7+ messages in thread From: Patrick Herbst @ 2020-05-29 2:54 UTC (permalink / raw) To: gcc-help I have the base gcc that came with my distro and i'd like to have the option of using a newer version without replacing the older one. I'd like to install the newer version in a different path, like /opt. I run into a problem though when compiling with the newer version in /opt, it links against the libstdc++ in /opt, but at runtime the executable tries to link with the systems version in /usr/lib. Is there a way to have the gcc in /opt automatically set the rpath when linking so that executables can run against the /opt libstdc++? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 2:54 multiple installed versions of gcc -- automatically set rpath ?? Patrick Herbst @ 2020-05-29 3:07 ` Dan Kegel 2020-05-29 9:28 ` Patrick Bégou 2020-05-29 11:22 ` Jonathan Wakely 2020-05-29 11:33 ` Jonathan Wakely 1 sibling, 2 replies; 7+ messages in thread From: Dan Kegel @ 2020-05-29 3:07 UTC (permalink / raw) To: Patrick Herbst; +Cc: gcc-help https://stackoverflow.com/questions/13334300/how-to-build-and-install-gcc-with-built-in-rpath is a bit dated, but might be helpful. It says in part:  Using --with-boot-ldflags="-Wl,-rpath,/some/path" on the configure step seems to work for me on gcc 4.8.3. The docs discuss this a bit https://gcc.gnu.org/install/configure.html - Dan On Thu, May 28, 2020 at 7:55 PM Patrick Herbst via Gcc-help <gcc-help@gcc.gnu.org> wrote: > > I have the base gcc that came with my distro and i'd like to have the > option of using a newer version without replacing the older one. > > I'd like to install the newer version in a different path, like /opt. > > I run into a problem though when compiling with the newer version in > /opt, it links against the libstdc++ in /opt, but at runtime the > executable tries to link with the systems version in /usr/lib. > > Is there a way to have the gcc in /opt automatically set the rpath > when linking so that executables can run against the /opt libstdc++? > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 3:07 ` Dan Kegel @ 2020-05-29 9:28 ` Patrick Bégou 2020-05-29 11:02 ` Thomas Doczkal 2020-05-29 11:22 ` Jonathan Wakely 1 sibling, 1 reply; 7+ messages in thread From: Patrick Bégou @ 2020-05-29 9:28 UTC (permalink / raw) To: gcc-help May be you can rely on the tool module-environment with linux. It allow you to set environments to use different versions of a same application. It is used on the french HPC centers and I use it to manage several paraview version and... several gcc/gfortran versions (4, 7, 9) on my servers and on the cluster. It is available in all linux distribution. Just load your tailored module (setting PATH, LD_LIBRARY_PATH....) to activate the gcc version needed and compile/execute On redhat 7 based OS look at environment-modules-3.2.10-10.el7.x86_64 Patrick Le 29/05/2020 à 05:07, Dan Kegel a écrit : > https://stackoverflow.com/questions/13334300/how-to-build-and-install-gcc-with-built-in-rpath > is a bit dated, but might be helpful. It says in part: >  > Using --with-boot-ldflags="-Wl,-rpath,/some/path" on the configure > step seems to work for me on gcc 4.8.3. The docs discuss this a bit > https://gcc.gnu.org/install/configure.html > > > - Dan > > On Thu, May 28, 2020 at 7:55 PM Patrick Herbst via Gcc-help > <gcc-help@gcc.gnu.org> wrote: >> I have the base gcc that came with my distro and i'd like to have the >> option of using a newer version without replacing the older one. >> >> I'd like to install the newer version in a different path, like /opt. >> >> I run into a problem though when compiling with the newer version in >> /opt, it links against the libstdc++ in /opt, but at runtime the >> executable tries to link with the systems version in /usr/lib. >> >> Is there a way to have the gcc in /opt automatically set the rpath >> when linking so that executables can run against the /opt libstdc++? >> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 9:28 ` Patrick Bégou @ 2020-05-29 11:02 ` Thomas Doczkal 0 siblings, 0 replies; 7+ messages in thread From: Thomas Doczkal @ 2020-05-29 11:02 UTC (permalink / raw) To: gcc-help [-- Attachment #1: Type: text/plain, Size: 1259 bytes --] On 5/29/20 11:28 AM, Patrick Bégou wrote: > Just load your tailored module (setting PATH, LD_LIBRARY_PATH....) to > activate the gcc version needed and compile/execute While setting LD_LIBRARY_PATH in modules is possible I see this with a grain of salt. It's tricky if you load two or more modules in the same shell. For what it's worth we change the rpath of the dynamically linked binaries with patchelf where possible. Regards Thomas -- Thomas Doczkal Snr System Engineer Socionext Europe GmbH pittlerstrasse 47 63225 langen, germany tel +49-6103-3745-386 mobile +49-174-9226082 fax +49-6103-3745-122 thomas.doczkal@socionext.com www.eu.socionext.com www.socionext.com Geschaeftsfuehrer/Managing Director: Toshihiko Tanaka, Dirk Weinsziehr, Koichi Otsuki, Yutaka Yoneyama Sitz/Seat: Langen, Hessen; Registergericht/Commercial Register: Offenbach/Main HRB 48005 This e-mail and any attachment contains information which is private and confidential and is intended for the addressee only. If you are not an addressee, you are not authorized to read, copy or use the e-mail or any attachment. If you have received this e-mail in error, please notify the sender by return e-mail and then delete it. [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 5154 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 3:07 ` Dan Kegel 2020-05-29 9:28 ` Patrick Bégou @ 2020-05-29 11:22 ` Jonathan Wakely 1 sibling, 0 replies; 7+ messages in thread From: Jonathan Wakely @ 2020-05-29 11:22 UTC (permalink / raw) To: Dan Kegel; +Cc: Patrick Herbst, gcc-help On Fri, 29 May 2020 at 04:53, Dan Kegel wrote: > > https://stackoverflow.com/questions/13334300/how-to-build-and-install-gcc-with-built-in-rpath > is a bit dated, but might be helpful. It says in part: >  > Using --with-boot-ldflags="-Wl,-rpath,/some/path" on the configure > step seems to work for me on gcc 4.8.3. The docs discuss this a bit > https://gcc.gnu.org/install/configure.html That sets the linker flags to use when building GCC itself. It doesn't make GCC automatically add those linker flags when you compile your own programs. Even if it did add the flags when compiling your own programs, it wouldn't work well for multlib compilers where the rpath should be lib or lib64 depending on the multilib being used for a given compilation. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 2:54 multiple installed versions of gcc -- automatically set rpath ?? Patrick Herbst 2020-05-29 3:07 ` Dan Kegel @ 2020-05-29 11:33 ` Jonathan Wakely 2020-05-29 17:23 ` Jonathan Wakely 1 sibling, 1 reply; 7+ messages in thread From: Jonathan Wakely @ 2020-05-29 11:33 UTC (permalink / raw) To: Patrick Herbst; +Cc: gcc-help On Fri, 29 May 2020 at 04:37, Patrick Herbst via Gcc-help <gcc-help@gcc.gnu.org> wrote: > > I have the base gcc that came with my distro and i'd like to have the > option of using a newer version without replacing the older one. > > I'd like to install the newer version in a different path, like /opt. > > I run into a problem though when compiling with the newer version in > /opt, it links against the libstdc++ in /opt, but at runtime the > executable tries to link with the systems version in /usr/lib. > > Is there a way to have the gcc in /opt automatically set the rpath > when linking so that executables can run against the /opt libstdc++? The simplest solution is to just use a shell script/function/alias to invoke the new GCC and have that automatically add the -Wl,-rpath flags. For example, I use this bash function: GCC () { local id=$1; local version=${id%/*}; shift; local dir=$HOME/gcc/${version}; local lib=lib64; for arg in "$@"; do case $arg in -m32) lib=lib ;; -m64) lib=lib64 ;; esac; done; local libdir=${id/$version/$dir\/$lib}; local colour=-fdiagnostics-color; if [[ $version =~ 4.[12345678] ]]; then colour=''; fi; ( set -o pipefail; LANG=C $dir/bin/g++ -Wall -Wextra -g "${@:--v}" ${@:+-Wl,-rpath,$libdir} $colour 2>&1 | less -FR ) } so that "GCC N ..." can be used to run ~/gcc/N/bin/g++ and set the rpath to ~/gcc/N/lib64 or ~/gcc/N/lib as appropriate. Then I haveshell aliases using that: g++14 is aliased to `GCC latest -std=gnu++14' g++17 is aliased to `GCC latest -std=gnu++17' where ~/gcc/latest is a symlink to (currently) ~/gcc/11 That shell function is overkill for most people (I have nearly 100 GCC builds under ~/gcc which is unusual!) but the general idea of a shortcut to invoke the new compiler with the -Wl,rpath option works well. You can also use a custom specs file, as shown in the stackoverflow link Dan Kegel gave (but ignore the answer there about --with-boost-ldflags as that's wrong). The answer showing how to use a specs file only works for non-multilib compilers though. If you want to be able to link both 32-bit and 64-bit code you'll need to make the link specs smarter, to adjust it based on the presence/absence of the -m64 or -m32 flags. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: multiple installed versions of gcc -- automatically set rpath ?? 2020-05-29 11:33 ` Jonathan Wakely @ 2020-05-29 17:23 ` Jonathan Wakely 0 siblings, 0 replies; 7+ messages in thread From: Jonathan Wakely @ 2020-05-29 17:23 UTC (permalink / raw) To: Patrick Herbst; +Cc: gcc-help On Fri, 29 May 2020 at 12:33, Jonathan Wakely <jwakely.gcc@gmail.com> wrote: > > On Fri, 29 May 2020 at 04:37, Patrick Herbst via Gcc-help > <gcc-help@gcc.gnu.org> wrote: > > > > I have the base gcc that came with my distro and i'd like to have the > > option of using a newer version without replacing the older one. > > > > I'd like to install the newer version in a different path, like /opt. > > > > I run into a problem though when compiling with the newer version in > > /opt, it links against the libstdc++ in /opt, but at runtime the > > executable tries to link with the systems version in /usr/lib. > > > > Is there a way to have the gcc in /opt automatically set the rpath > > when linking so that executables can run against the /opt libstdc++? > > > The simplest solution is to just use a shell script/function/alias to > invoke the new GCC and have that automatically add the -Wl,-rpath > flags. For example, I use this bash function: > > GCC () > { > local id=$1; > local version=${id%/*}; > shift; > local dir=$HOME/gcc/${version}; > local lib=lib64; > for arg in "$@"; > do > case $arg in > -m32) > lib=lib > ;; > -m64) > lib=lib64 > ;; > esac; > done; > local libdir=${id/$version/$dir\/$lib}; > local colour=-fdiagnostics-color; > if [[ $version =~ 4.[12345678] ]]; then > colour=''; > fi; > ( set -o pipefail; > LANG=C $dir/bin/g++ -Wall -Wextra -g "${@:--v}" > ${@:+-Wl,-rpath,$libdir} $colour 2>&1 | less -FR ) > } > > so that "GCC N ..." can be used to run ~/gcc/N/bin/g++ and set the > rpath to ~/gcc/N/lib64 or ~/gcc/N/lib as appropriate. Then I haveshell > aliases using that: > > g++14 is aliased to `GCC latest -std=gnu++14' > g++17 is aliased to `GCC latest -std=gnu++17' > > where ~/gcc/latest is a symlink to (currently) ~/gcc/11 > > That shell function is overkill for most people (I have nearly 100 GCC > builds under ~/gcc which is unusual!) but the general idea of a > shortcut to invoke the new compiler with the -Wl,rpath option works > well. > > > You can also use a custom specs file, as shown in the stackoverflow > link Dan Kegel gave (but ignore the answer there about > --with-boost-ldflags as that's wrong). The answer showing how to use a > specs file only works for non-multilib compilers though. If you want > to be able to link both 32-bit and 64-bit code you'll need to make the > link specs smarter, to adjust it based on the presence/absence of the > -m64 or -m32 flags. It looks like this works for the multilib case: --with-specs='%{!static:%{!m32:-Wl,-rpath,/tmp/rpathinst/lib64}%{m32:-Wl,-rpath,/tmp/rpathinst/lib}}' It assumes you know the /tmp/rpathinst prefix in advance, so isn't perfect. I'd like it to be able to find the lib and lib64 dirs relative to the installation dir. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-05-29 17:23 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-05-29 2:54 multiple installed versions of gcc -- automatically set rpath ?? Patrick Herbst 2020-05-29 3:07 ` Dan Kegel 2020-05-29 9:28 ` Patrick Bégou 2020-05-29 11:02 ` Thomas Doczkal 2020-05-29 11:22 ` Jonathan Wakely 2020-05-29 11:33 ` Jonathan Wakely 2020-05-29 17:23 ` Jonathan Wakely
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).