Discussion:
Setting the dynamic linker with an environment variable
Shaun Jackman
2014-09-09 22:30:46 UTC
Permalink
The linker option -L can be set with the environment variable
LIBRARY_PATH, and the linker option -Wl,-rpath can be set with the
LD_RUN_PATH environment variable. Is there an environment variable to
set the -Wl,--dynamic-linker option? It would be useful for compiling
stubborn packages that don't respect the LDFLAGS environment variable.
(openssl is one such stubborn package, I've discovered).

Alternatively, how can I modify the default `specs` file of GCC to add
to the default linker options
-L$prefix/lib -Wl,-rpath,$prefix/lib -Wl,--dynamic-linker
$prefix/lib/ld-linux-x86-64.so.2

Thanks,
Shaun

https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
http://manpages.ubuntu.com/manpages/lucid/man1/ld.1.html
http://en.wikipedia.org/wiki/Rpath
Ian Lance Taylor
2014-09-10 00:13:00 UTC
Permalink
Post by Shaun Jackman
Is there an environment variable to
set the -Wl,--dynamic-linker option?
No. That's a fairly unusual thing to want to do.
Post by Shaun Jackman
Alternatively, how can I modify the default `specs` file of GCC to add
to the default linker options
-L$prefix/lib -Wl,-rpath,$prefix/lib -Wl,--dynamic-linker
$prefix/lib/ld-linux-x86-64.so.2
If you want to go that route, add it to the line after "*link:" in the
specs file.

Ian
Shaun Jackman
2014-09-10 17:59:41 UTC
Permalink
Post by Ian Lance Taylor
Post by Shaun Jackman
Alternatively, how can I modify the default `specs` file of GCC to add
to the default linker options
-L$prefix/lib -Wl,-rpath,$prefix/lib -Wl,--dynamic-linker
$prefix/lib/ld-linux-x86-64.so.2
If you want to go that route, add it to the line after "*link:" in the
specs file.
That worked like a charm! Thanks, Ian. I replaced the link spec like so:

*link:
-L/home/sjackman/.linuxbrew/lib -rpath /home/sjackman/.linuxbrew/lib
--dynamic-linker /home/sjackman/.linuxbrew/lib/ld-linux-x86-64.so.2

How do I remove the following four directories from the library search
path, while still retaining the $prefix/lib and $prefix/lib/gcc/*
directories?

/lib64 /usr/lib64 /lib /usr/lib

Thanks again,
Shaun
Shaun Jackman
2014-09-10 22:28:24 UTC
Permalink
Post by Shaun Jackman
Post by Ian Lance Taylor
Post by Shaun Jackman
Alternatively, how can I modify the default `specs` file of GCC to add
to the default linker options
-L$prefix/lib -Wl,-rpath,$prefix/lib -Wl,--dynamic-linker
$prefix/lib/ld-linux-x86-64.so.2
If you want to go that route, add it to the line after "*link:" in the
specs file.
-L/home/sjackman/.linuxbrew/lib -rpath /home/sjackman/.linuxbrew/lib
--dynamic-linker /home/sjackman/.linuxbrew/lib/ld-linux-x86-64.so.2
Note that replacing the link spec is a patently bad idea and breaks
building shared libraries (and probably other things). I should have
appended to the link spec by using the `+' function.

*link:
+ -L/home/sjackman/.linuxbrew/lib -rpath /home/sjackman/.linuxbrew/lib
--dynamic-linker /home/sjackman/.linuxbrew/lib/ld-linux-x86-64.so.2

Cheers,
Shaun
Shaun Jackman
2014-09-12 18:26:34 UTC
Permalink
Post by Shaun Jackman
How do I remove the following four directories from the library search
path, while still retaining the $prefix/lib and $prefix/lib/gcc/*
directories?
/lib64 /usr/lib64 /lib /usr/lib
To override the standard search directories, I added `-nostdlib` to
the `link_libgcc` spec.

*link_libgcc:
-nostdlib -L/home/sjackman/.linuxbrew/Cellar/gcc/4.9.1/lib/gcc/x86_64-unknown-linux-gnu/4.9.1
-L/home/sjackman/.linuxbrew/lib

*link:
+ -rpath /home/sjackman/.linuxbrew/lib --dynamic-linker
/home/sjackman/.linuxbrew/opt/glibc/lib/ld-linux-x86-64.so.2

Cheers,
Shaun

Loading...