LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Which dynamic library is being used? (https://www.linuxquestions.org/questions/linux-software-2/which-dynamic-library-is-being-used-758796/)

sysbox 09-30-2009 07:08 PM

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?

JWPurple 09-30-2009 07:11 PM

ldd <executable>

sysbox 09-30-2009 07:17 PM

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.

lutusp 10-01-2009 02:50 AM

Quote:

Originally Posted by sysbox (Post 3702574)
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 (Post 3702574)
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 (Post 3702574)
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.

sysbox 10-01-2009 12:46 PM

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.

chrism01 10-01-2009 07:39 PM

According to this http://linux.die.net/man/1/ldd you can in fact pass a lib name to ldd as well.

sysbox 10-06-2009 01:06 PM

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.


All times are GMT -5. The time now is 04:28 PM.