View previous topic :: View next topic |
Author |
Message |
ONEEYEMAN Advocate
Joined: 01 Mar 2005 Posts: 3610
|
Posted: Thu May 24, 2018 5:14 am Post subject: Ld_library_path |
|
|
Hi,
I just rebooted my Gentoo Laptop and after the reboot I issued:
Code: |
echo $LD_LIBRARY_PATH
|
and I got empty string.
So, it means that this variable doesn't contain anything by default? And if I put something in it storing it in the .bash.profile I won't override anything?
But then how the dynamic linking is done?
Thank you. |
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 30917 Location: here
|
Posted: Thu May 24, 2018 5:37 am Post subject: |
|
|
See
_________________ Questions are guaranteed in life; Answers aren't. |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Thu May 24, 2018 9:28 am Post subject: |
|
|
Quote: | So, it means that this variable doesn't contain anything by default? |
LD_LIBRARY_PATH is undefined or empty on some systems and non-empty on other systems...
Quote: | And if I put something in it storing it in the .bash.profile I won't override anything? |
Use the code below in .bash.profile to make sure that you don't override an existing value:
Code: | export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:<your path>" |
|
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Thu May 24, 2018 9:52 am Post subject: |
|
|
You have the /etc/ld.so.conf.d directory for that.
And on gentoo, it could also be made with /etc/env.d (which are add to ld.so.conf by env-update command).
While it could be made like mike155 shown, i think many users are just putting way too much inside .bash.profile, making them forget about it as the file is getting a piece of spaghetti. |
|
Back to top |
|
|
ONEEYEMAN Advocate
Joined: 01 Mar 2005 Posts: 3610
|
Posted: Thu May 24, 2018 3:24 pm Post subject: |
|
|
Hi,
mike155 wrote: |
Quote: |
So, it means that this variable doesn't contain anything by default?
|
LD_LIBRARY_PATH is undefined or empty on some systems and non-empty on other systems...
Quote: |
And if I put something in it storing it in the .bash.profile I won't override anything?
|
Use the code below in .bash.profile to make sure that you don't override an existing value:
Code: |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:<your path>"
|
|
Yes, that code solved it.
Thank you. |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21635
|
Posted: Fri May 25, 2018 1:34 am Post subject: |
|
|
mike155 wrote: | Use the code below in .bash.profile to make sure that you don't override an existing value:
Code: | export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:<your path>" |
| Although common advice, this is technically wrong. glibc has a long-standing, and in my opinion extremely dangerous and misguided, rule that blank elements in certain paths, including $LD_LIBRARY_PATH, result in searching the current directory. Code: | $ cd $(mktemp -d)
$ ls -l
total 0
$ touch libc.so.6
$ /bin/true
$ /usr/bin/env /bin/true
$ /usr/bin/env LD_LIBRARY_PATH=:/lib /bin/true
/bin/true: error while loading shared libraries: libc.so.6: file too short | Therefore, users must always take care not to create blank elements in $LD_LIBRARY_PATH (and also $PATH, and possibly others). Your example will create a blank leading element if $LD_LIBRARY_PATH was previously unset or empty. |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Fri May 25, 2018 2:17 am Post subject: |
|
|
@Hu: thanks for pointing this out! I didn't know that. I have always believed that '.' means 'current directory'. That's really DANGEROUS! |
|
Back to top |
|
|
ONEEYEMAN Advocate
Joined: 01 Mar 2005 Posts: 3610
|
Posted: Fri May 25, 2018 5:27 pm Post subject: |
|
|
Hi,
@Hu, so what is the proper way of doing it?
Thank you. |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Fri May 25, 2018 6:25 pm Post subject: |
|
|
ONEEYEMAN wrote: | So, what is the proper way of doing it? |
There are many ways. Perhaps the simplest completely POSIX compliant is
Code: | LD_LIBRARY_PATH=${LD_LIBRARY_PATH-}${LD_LIBRARY_PATH:+:}'<your path>'
export LD_LIBRARY_PATH |
Note that the first "-" is needed if you should run the code with set -u.
Note also that the separate commands for variable assignment and export are needed for POSIX compliance and in addition save you from unnecessary quoting |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Fri May 25, 2018 9:51 pm Post subject: |
|
|
et al ... thankfully I've never had to consider the "proper" way of doing this (until now) ...
Code: | % echo $0
/bin/zsh
% typeset -T LD_LIBRARY_PATH ld_library_path :
% ld_library_path+=(/lib /usr/local/lib)
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib |
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sat May 26, 2018 6:57 am Post subject: |
|
|
khayyam wrote: | Code: | % typeset -T LD_LIBRARY_PATH ld_library_path |
|
Perhaps better Code: | % typeset -xT LD_LIBRARAY_PATH ld_library_path | or - why not using the features of a luxury shell - also using option -U so that duplicate paths are avoided automatically. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat May 26, 2018 8:40 am Post subject: |
|
|
mv wrote: | Perhaps better
Code: | % typeset -xT LD_LIBRARAY_PATH ld_library_path |
|
mv ... did you try?
Code: | % typeset -xT LD_LIBRARY_PATH ld_library_path :
% ld_library_path+=(/lib /usr/local/lib)
% echo $LD_LIBRARY_PATH
% typeset -x LD_LIBRARY_PATH
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib |
If you want that then you need to 'typeset -T +x'
mv wrote: | or - why not using the features of a luxury shell - also using option -U so that duplicate paths are avoided automatically. |
You would need to do this after the asignment, otherwise there is only the previous value to check for dups.
Code: | % typeset -T +Ux LD_LIBRARY_PATH ld_library_path :
% ld_library_path+=(/lib /usr/local/lib)
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib
% ld_library_path+=/lib
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib:/lib
% typeset -U LD_LIBRARY_PATH
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib |
Anyhow, all I intended to demonstrate was -T, and how it's use allows the var/array to be manipulated without the problem Hu pointed to ...
man zshbuiltins wrote: | In cases where there are two parameters with an upper and lowercase form of the same name, such as path and PATH, the lowercase form is an array and the uppercase form is a scalar with the elements of the array joined together by colons. These are similar to tied parameters created via `typeset -T'. The normal use for the colon-separated form is for exporting to the environment, while the array form is easier to manipulate within the shell. |
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sat May 26, 2018 10:26 am Post subject: |
|
|
khayyam wrote: | Code: | % typeset -xT LD_LIBRARAY_PATH ld_library_path |
mv ... did you try? |
No; I only copied from the manpage:
zsh manpage wrote: | Note that both `typeset -xT ...' and `export -T ...' work, but only the scalar will be marked for export |
A bug in the manpage?
Quote: | You would need to do this after the asignment, otherwise there is only the previous value to check for dups. |
To my understanding, "unique array" is a zsh type which is always active:
Code: | % typeset -UT A a
% a=(1 2 3 1 4)
% echo $A
1:2:3:4
% a+=1
% echo $A
1:2:3:4 |
|
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat May 26, 2018 2:09 pm Post subject: |
|
|
mv wrote: | zsh manpage wrote: | Note that both `typeset -xT ...' and `export -T ...' work, but only the scalar will be marked for export |
A bug in the manpage? |
mv ... yes, I think it is, because the scalar isn't exported in that case:
Code: | % typeset -xT LD_LIBRARY_PATH ld_library_path=(/lib /usr/local/lib) :
% echo $LD_LIBRARY_PATH
% echo $ld_library_path
/lib /usr/local/lib |
mv wrote: | To my understanding, "unique array" is a zsh type which is always active:
Code: | % typeset -UT A a
% a=(1 2 3 1 4)
% echo $A
1:2:3:4
% a+=1
% echo $A
1:2:3:4 |
|
You're absolutely right ... counterintuatively '+' turns the attribute off.
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sat May 26, 2018 5:07 pm Post subject: |
|
|
khayyam wrote: | Code: | % typeset -xT LD_LIBRARY_PATH ld_library_path=(/lib /usr/local/lib) :
% echo $LD_LIBRARY_PATH |
|
Here (zsh-5.5.1) it seems to work:
Code: | % typeset -xT LD_LIBRARY_PATH ld_library_path=(/lib /usr/local/lib) :
% echo $LD_LIBRARY_PATH
/lib:/usr/local/lib
% sh -c 'echo $LD_LIBRARY_PATH'
/lib:/usr/local/lib |
|
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat May 26, 2018 8:57 pm Post subject: |
|
|
mv wrote: | Here (zsh-5.5.1) it seems to work: |
mv ... same version here, and it works if I call zsh with norc ... that suggests something in my env, not sure what though.
best ... khay |
|
Back to top |
|
|
|