LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-30-2009, 07:08 PM   #1
sysbox
Member
 
Registered: Jul 2005
Posts: 117

Rep: Reputation: 15
Which dynamic library is being used?


Is there an equivalent to "which" that will tell me, which dynamic/shared library will be loaded by an executable at runtime? For example, "which libwhatever.so" would determine, based on environment variables and system defaults, the locations of the libwhatever.so that will be loaded by an exeuctable at runtime?
 
Old 09-30-2009, 07:11 PM   #2
JWPurple
Member
 
Registered: Feb 2008
Posts: 67

Rep: Reputation: 17
ldd <executable>
 
Old 09-30-2009, 07:17 PM   #3
sysbox
Member
 
Registered: Jul 2005
Posts: 117

Original Poster
Rep: Reputation: 15
I'm aware of ldd. It takes the executable as an argument, not the name of a dynamic library.

How does ldd figure out which dynamic library to use? I'd like to know if there is a tool that does that.
 
Old 10-01-2009, 02:50 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by sysbox View Post
I'm aware of ldd. It takes the executable as an argument, not the name of a dynamic library.
Yes, and then it examines the executable file whose name you pass it to figure out which libraries that executable requires, which is what you asked for.

Quote:
Originally Posted by sysbox View Post
How does ldd figure out which dynamic library to use?
It examines the executable file you pass it as an argument, determines which libraries it requires, and prints them out.

Quote:
Originally Posted by sysbox View Post
I'd like to know if there is a tool that does that.
There is! It's called "ldd". Here's how it works:

Code:
$ ldd /bin/bash
        linux-gate.so.1 =>  (0x00ee3000)
        libtinfo.so.5 => /lib/libtinfo.so.5 (0x06ed7000)
        libdl.so.2 => /lib/libdl.so.2 (0x008c9000)
        libc.so.6 => /lib/libc.so.6 (0x0072c000)
        /lib/ld-linux.so.2 (0x00708000)
Summary: The user types in "ldd" followed by the name of an executable. "ldd" examines the file whose name you give it an prints out a list of the libraries required by the executable.

Which is what you asked for.
 
Old 10-01-2009, 12:46 PM   #5
sysbox
Member
 
Registered: Jul 2005
Posts: 117

Original Poster
Rep: Reputation: 15
I guess I'm not making myself clear. I'm looking for a tool that takes only the dynamic library name, and not an executable name, as an argument, and figures out which actual library will be loaded by a hypothetical executable at run-time. Don't assume that I have an existing executable that needs that library: but if I did, you're right, ldd would work fine.

I could write a Perl script that searches the LD_LIBRARY_PATH, and it would be fairly trivial. But since ldd (and ld.so) must already do this,
I thought that maybe such a tool already existed.

Anyway, thanks for your help.
 
Old 10-01-2009, 07:39 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,860

Rep: Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596
According to this http://linux.die.net/man/1/ldd you can in fact pass a lib name to ldd as well.
 
Old 10-06-2009, 01:06 PM   #7
sysbox
Member
 
Registered: Jul 2005
Posts: 117

Original Poster
Rep: Reputation: 15
A good solution to this was provided in another thread by lutusp, who also responded to this thread: whereis. That locates more than just binary executables, but include files and library files as well.

Thanks for all the help.
 
  


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
Getting Base Address of Dynamic Library Damaged Soul Programming 11 12-13-2010 01:28 PM
C++ and dynamic library loading Osiris990 Programming 5 11-08-2007 11:07 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
Linking a static library to a dynamic one delta4s Programming 2 09-28-2006 01:24 AM
dynamic library versioning kev82 Linux - General 9 12-13-2003 09:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:44 AM.

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