Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlopen() search path

Tags:

c

linux

dlopen

is there a way to find out programmatically which paths are searched by dlopen() for shared objects? I always thought dlopen() would only look in /lib and /usr/lib but now I've seen that on Linux Mint several core components like libglib-2.0.so are in a wholly different folders, namely in /rofs/lib/i386-gnu-linux and some others. Is there a way to get to know all these paths that dlopen() will search through for a shared object? I already checked the environment variable LD_LIBRARY_PATH but it's not defined at all.

like image 888
user1055225 Avatar asked Nov 19 '11 11:11

user1055225


People also ask

Where does Dlopen look library?

Otherwise, dlopen() will search for the library in the following order: A colon-separated list of directories in the user's LD_LIBRARY_PATH environment variable. The list of libraries specified in /etc/ld.

What is dlopen()?

The dlopen() function shall make an executable object file specified by file available to the calling program.

What happens if Dlopen is called twice?

If the same library is loaded again with dlopen(), the same file handle is returned. The dl library maintains reference counts for library handles, so a dynamic library is not deallocated until dlclose() has been called on it as many times as dlopen() has succeeded on it.

How do I check my Dlopen error?

Since the value of the symbol could actually be NULL (so that a NULL return from dlsym() need not indicate an error), the correct way to test for an error is to call dlerror() to clear any old error conditions, then call dlsym(), and then call dlerror() again, saving its return value into a variable, and check whether ...


2 Answers

look at the ldconfig man page, and the file: /etc/ld.so.conf

like image 182
Brett Hale Avatar answered Oct 09 '22 19:10

Brett Hale


In addition of the ld.so.conf hint:

If you want to ensure that a specific library is dlopen-ed, pass a path to dlopen, e.g. dlopen("/some/path/to/lib.so", RTLD_LOCAL) or maybe dlopen("./lib.so", RTLD_LOCAL) but not dlopen("lib.so", RTLD_LOCAL)

If on Linux, read the man page dlopen(3)

like image 6
Basile Starynkevitch Avatar answered Oct 09 '22 21:10

Basile Starynkevitch