Will dlopen produce the same descriptor for two calls with the same file?

If I use dlopen in the same lib / file twice in the same application, will it work with the same descriptor in both cases? Is there any guarantee for this (a short experiment showed what it at least does on my box)?

I am currently playing with a small plug-in system (out of curiosity), and if there is some guarantee for this observable behavior, I can use this address as a key for the plug-in to prevent duplication of loads.

+5
source share
1 answer

Yes. dlopen (3) The personal linux page says:

   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.

BTW, Linux ( ) , manydl.c . - . dlclose.

( dlopen-ed )

2017 :

, , dlopen. , "./foo.so" "././foo.so" ( "../foosymlink.so", foosymlink.so foo.so), - , .

+8

All Articles