Home > Blockchain >  Linux and shared libraries, linking vs dlopen - symbol visibility
Linux and shared libraries, linking vs dlopen - symbol visibility

Time:12-04

I work on Linux. When my application links to the shared library (which doesn't hide symbols) all symbols from that library are visible. A shared library can also be loaded at runtime using dlopen. Is it possible to control symbols visiblity using dlopen mode parameter or I always have to get desire symbol using dlsym ?

CodePudding user response:

Your question is exceedingly unclear.

If you dlopen the library, then about the only way to get to any of its symbols is via dlsym.

However, if you dlopen a library with RTLD_GLOBAL, then its symbols become available for subsequently loaded libraries without using dlsym.

For example, if libfoo.so defines symbol foo, and if you dlopen("libfoo.so", RTLD_GLOBAL|...); and later dlopen("libbar.so", ...) which uses foo, that would work -- libbar.so will be able to use foo from libfoo.so without doing any dlsym calls.

  • Related