Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Ld_library_path
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 2720

PostPosted: Thu May 24, 2018 5:14 am    Post subject: Ld_library_path Reply with quote

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
View user's profile Send private message
fedeliallalinea
Bodhisattva
Bodhisattva


Joined: 08 Mar 2003
Posts: 19441
Location: here

PostPosted: Thu May 24, 2018 5:37 am    Post subject: Reply with quote

See
Code:
man ld.so

_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
mike155
Guru
Guru


Joined: 17 Sep 2010
Posts: 548
Location: Frankfurt, Germany

PostPosted: Thu May 24, 2018 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 6814

PostPosted: Thu May 24, 2018 9:52 am    Post subject: Reply with quote

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
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 2720

PostPosted: Thu May 24, 2018 3:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 12707

PostPosted: Fri May 25, 2018 1:34 am    Post subject: Reply with quote

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
View user's profile Send private message
mike155
Guru
Guru


Joined: 17 Sep 2010
Posts: 548
Location: Frankfurt, Germany

PostPosted: Fri May 25, 2018 2:17 am    Post subject: Reply with quote

@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
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 2720

PostPosted: Fri May 25, 2018 5:27 pm    Post subject: Reply with quote

Hi,
@Hu, so what is the proper way of doing it?

Thank you.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6184

PostPosted: Fri May 25, 2018 6:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6063
Location: Room 101

PostPosted: Fri May 25, 2018 9:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6184

PostPosted: Sat May 26, 2018 6:57 am    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6063
Location: Room 101

PostPosted: Sat May 26, 2018 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6184

PostPosted: Sat May 26, 2018 10:26 am    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6063
Location: Room 101

PostPosted: Sat May 26, 2018 2:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6184

PostPosted: Sat May 26, 2018 5:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6063
Location: Room 101

PostPosted: Sat May 26, 2018 8:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum