Given the following library :
libfoo.{so,dll,dylib}:
const char* get_lib_path() {
return ...;
}
built as a shared library (for instance with GCC) :
gcc -shared -fPIC foo.cpp -o libfoo.so
is there a way to get get_lib_path()
to return, at runtime, the path where the library resides on the file system, whether on Windows, macOS, Linux ?
The final name of the library is not known : I can't assume a search of the string "libfoo.so" from the list of the loaded libraries.
This must not require the native handle to the dynamically loaded object: I want to know the path from inside my library, and I do not have control over the application that loads it (so I can't get the dlopen
handle for instance).