K
K
Kirill Nesmeyanov2021-07-25 02:52:47
linux
Kirill Nesmeyanov, 2021-07-25 02:52:47

How to get full path to so library?

According to the manual, the " dlopen " function allows you to connect so by passing the name of the library there. Then it searches and connects this very library.

However, having looked through the manual, I did not find a single function that would return the real physical location of the library by this very name. Something like dlfind("some.so"); // => /usr/lib/some.so.3

The only option I came up with is to run the " strings -n5 /etc/ld.so.cache " process, then get a list of all possible directories with simple manipulations and find the necessary so there .

However, the problems with this approach are:
1) Creating a child process, which I don't really like
2) The file " ld.so.cache"may not exist physically (well, for example, someone slammed it), while dlopen continues to work remarkably well.

Poke into the manual pliz, how to get the full path to the * .so library by its name? Well, or how to get a list of all directories where there may be these libs: Then by simple enumeration you can find the full path by hand

PS Another variant of manual reading /etc/ld.so.conf came up .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2021-07-25
@gbg

dladdr produces a structure that contains the full path to .so

typedef struct {
               const char *dli_fname;  /* Pathname of shared object that
                                          contains address */
               void       *dli_fbase;  /* Base address at which shared
                                          object is loaded */
               const char *dli_sname;  /* Name of symbol whose definition
                                          overlaps addr */
               void       *dli_saddr;  /* Exact address of symbol named
                                          in dli_sname */
           } Dl_info;

F
Fenrir89, 2021-07-26
@Fenrir89

find / -type f -name "file.so"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question