[Tips] How to quickly locate a shared library under Linux __linux

Source: Internet
Author: User

In some cases, you might want to know which directory my program links to.


There are three ways to deal with this easily.

1. LDD command

$ LDD App

2. Static Lookup

$ locate Lib_name

3. Dynamic implementation

$ strace App 2>&1 | grep lib_name


Let me give you an example.

Ubuntu's 64-bit LS is linked to the Libselinux.so.1 library.

So we're going to find out where this library is.

1. ldd

$ ldd/bin/ls

Libselinux.so.1 =>/lib64/libselinux.so.1 (0x00007f97dd5a9000)

In addition, if LDD finds a library that is not found, you can use Ldd-r to print out specific symbols.

Like what:

# ldd-r/test.
Linux-vdso.so.1 => (0x00007fff8a32b000)
Libfoo.so => not found
Libc.so.6 =>/lib64/libc.so.6 (0x00007fef5bfa9000)
/lib64/ld-linux-x86-64.so.2 (0x00007fef5c352000)
Undefined Symbol:foo (./test)


2. Static Lookup

$ locate Libselinux.so.1

/lib/i386-linux-gnu/libselinux.so.1
/lib/x86_64-linux-gnu/libselinux.so.1

We can see that there are two positions, one is the bit and the other is the bit.

Because we know that LS is 64 bits, the corresponding library should be:/lib/x86_64-linux-gnu/libselinux.so.1

3. Dynamic implementation

$ strace ls 2>&1 | grep libselinux.so.1

Open ("/lib/x86_64-linux-gnu/libselinux.so.1", o_rdonly| O_CLOEXEC) = 3

Through open this system call we know the use is:/lib/x86_64-linux-gnu/libselinux.so.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.