LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2021, 07:53 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Rep: Reputation: 8
Where do binaries look for shared libraries ?


Dear LQ,

Where do binaries look for shared libraries ? and can I somehow control/change that ?
 
Old 09-01-2021, 08:13 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,707
Blog Entries: 16

Rep: Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385Reputation: 3385
Yes, very easily. A program called ldconfig keeps a database in /etc/ld.so.cache and is controlled by a configuration file in /etc/ld.so.conf. My config file reads:
Code:
/lib64
/usr/lib64
/usr/local/lib64
/usr/x86_64-slackware-linux/lib64
/usr/lib64/java/lib/amd64
/usr/lib64/firefox
ldconfig is always run after updating a library and most distros run it at boot time too. If you want additional locations to be recognised, put them in the .conf file, then run ldconfig again.
 
1 members found this post helpful.
Old 09-01-2021, 08:49 AM   #3
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
Thanks a ton hazel. Is it safe to put "." in there ? The idea is to use a newer
version of a library for some new software installed on some local directory,
while keeping the old version untouched for the rest of the system.
 
Old 09-01-2021, 08:51 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,862

Rep: Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694
you can try to set the variable LD_LIBRARY_PATH before executing your binary. But I wouldn't add . to that cache.
 
2 members found this post helpful.
Old 09-01-2021, 08:57 AM   #5
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
My system seems to have an empty LD_LIBRARY_PATH I wish I could
do as with PATH variable (PATH=.:$PATH), but in the case of
LD_LIBRARY_PATH it seems I need to add all the paths.
 
Old 09-01-2021, 08:58 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,862

Rep: Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694Reputation: 5694
no, you do not need to add system dirs to that variable. Probably . is enough. Just test it.
 
Old 09-01-2021, 09:07 AM   #7
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
I did, but it seems it can't find the new library. I would like to see that with strace but I don't know the right way to do it

Code:
ychaouche#ychaouche-PC 15:07:04 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ strace -f LD_LIBRARY_PATH=. teamviewer
strace: Can't stat 'LD_LIBRARY_PATH=.': No such file or directory
ychaouche#ychaouche-PC 15:07:05 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $
 
Old 09-01-2021, 09:10 AM   #8
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
I tried with bash export, now I can see that I need to rename the library to libfreetype.so.6 -instead of .6.12.3-

Code:
ychaouche#ychaouche-PC 15:08:17 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ strace -f teamviewer 2>&1 | grep freetype
[pid 16510] open("./tls/x86_64/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("./tls/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("./x86_64/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("./libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("/opt/teamviewer/tv_bin/RTlib/qt/plugins/platforms/../../lib/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("/opt/teamviewer/tv_bin/RTlib/qt/plugins/platforms/../../../libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 16510] open("/usr/lib/x86_64-linux-gnu/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = 9
ychaouche#ychaouche-PC 15:08:29 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $
 
Old 09-01-2021, 09:13 AM   #9
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 1,631

Rep: Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330Reputation: 1330

I'm guessing you still haven't bothered making use of TeamViewer Support yet?


Last edited by boughtonp; 09-01-2021 at 09:14 AM.
 
Old 09-01-2021, 09:13 AM   #10
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
Oh, even after renaming the file is not found

Code:
ychaouche#ychaouche-PC 15:08:29 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ ls
total 700K
-rw-r--r-- 1 ychaouche ychaouche 700K Oct 23  2020 libfreetype.so.6.12.3
ychaouche#ychaouche-PC 15:09:20 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ ln -s libfreetype.so.6.12.3  libfreetype.so.6
ychaouche#ychaouche-PC 15:11:06 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ teamviewer

Init...
CheckCPU: SSE2 support: yes
Checking setup...
Launching TeamViewer ...
Launching TeamViewer GUI ...
ychaouche#ychaouche-PC 15:11:09 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ strace teamviewer 2>&1 | grep libfreetype
open("./tls/x86_64/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("./tls/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("./x86_64/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("./libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/teamviewer/tv_bin/RTlib/qt/plugins/platforms/../../lib/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/teamviewer/tv_bin/RTlib/qt/plugins/platforms/../../../libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libfreetype.so.6", O_RDONLY|O_CLOEXEC) = 9
ychaouche#ychaouche-PC 15:11:30 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ ls
total 700K
lrwxrwxrwx 1 ychaouche ychaouche   21 Sep  1 15:11 libfreetype.so.6 -> libfreetype.so.6.12.3
-rw-r--r-- 1 ychaouche ychaouche 700K Oct 23  2020 libfreetype.so.6.12.3
ychaouche#ychaouche-PC 15:11:41 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $
Maybe "." doesn't have the meaning I expected. Is it the directory from where the
binary is run (my current pwd), or is it where the binary lives (path to the
binary) ?
 
Old 09-01-2021, 09:34 AM   #11
enigma9o7
Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 611

Rep: Reputation: 223Reputation: 223Reputation: 223
. is present working directory.

If you are launching from command line, its the folder you're in. If from desktop file, there's a "PATH=" entry if you want it to change to certain folder first.

You should not rename, you should simlink, which is what would happen if you installed it from a a package instead of manually. Have you even found that 'tls' folder it's looking in?

Why not just specify the exact path tho to be sure.
 
1 members found this post helpful.
Old 09-01-2021, 09:39 AM   #12
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
@enigma9o7

It's looking at many places, including "."

Code:
open("./libfreetype.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
Yes I created the symlink, see trace above, and below :

Code:
ychaouche#ychaouche-PC 15:08:29 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ ls
total 700K
-rw-r--r-- 1 ychaouche ychaouche 700K Oct 23  2020 libfreetype.so.6.12.3
ychaouche#ychaouche-PC 15:09:20 ~/DOWNLOADS/LIBS/FREETYPE2.6/usr/lib/x86_64-linux-gnu $ ln -s libfreetype.so.6.12.3  libfreetype.so.6
Quote:
Why not just specify the exact path tho to be sure.
Thanks for the suggestion. If I add the full path it works just fine. I'll mark this thread as solved.
 
1 members found this post helpful.
Old 09-07-2021, 01:03 PM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,292
Blog Entries: 4

Rep: Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318
Also please note that Linux has a ldconfig command which must be run (by root ...) after changing any of these sources. This command re-creates the cache that is actually used by the linker to resolve dependencies.

Unlike (say ...) Windows, Linux/Unix has a very elaborate system by which an application can specify its external-library requirements. The cache enables the loader to resolve these issues expediently. (Installation scripts routinely invoke this command, but you can do it too.)

Last edited by sundialsvcs; 09-07-2021 at 01:06 PM.
 
Old 09-08-2021, 12:17 AM   #14
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,206
Blog Entries: 1

Rep: Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565
When building your executables, option `-Wl,-rpath,/some/path` can be used to specify run-time resolve directories (there used to be a `-R/some/path` option, but it was too easy to use).

You can use `readelf` to check it:
Code:
$ readelf -d /usr/local/bin/openssl |grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [/usr/local/lib64]

Last edited by NevemTeve; 09-08-2021 at 05:37 AM.
 
Old 09-08-2021, 04:21 AM   #15
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 160

Original Poster
Rep: Reputation: 8
Thanks sundialsvcs, but I don't want the whole system to be aware of the library.
I only want one specific binary to use the new library, while the rest of the
system runs the old version.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Chrome binaries always work on older systems but Firefox binaries do not - what is the magic? Jason_25 Linux - Software 1 10-28-2019 11:23 AM
Static libraries vs shared Libraries catallergy Linux - Newbie 2 03-16-2010 01:30 PM
Urgent !!! rpm: error while loading shared libraries: libelf.so.1: cannot open shared tinaa Linux - Software 5 12-02-2008 03:19 PM
Build i386 binaries based on i386 shared libraries .so linuxcrazyguy Linux - Software 0 03-19-2007 05:27 PM
linux init error in loading shared shared libraries akaran Linux - Software 1 05-28-2003 04:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration