POSIX function to dynamically load a library or binary into memory
Questions tagged [dlopen]
685 questions
12
votes
3 answers
How to get the absolute library file name corresponding to a relative path given to dlopen?
In my program I have code like the following
/* libname may be a relative path */
void loadLib(char const *libname) {
void *handle = dlopen(libname);
/* ... */
dlclose(handle);
}
Within /* .. */, I need to read the memory map file…

Johannes Schaub - litb
- 496,577
- 130
- 894
- 1,212
12
votes
3 answers
Is there an elegant way to avoid dlsym when using dlopen in C?
I need to dynamically open a shared library lib.so if a specific condition is met at runtime. The library contains ~700 functions and I need to load all their symbols.
A simple solution is to define the function pointers to all symbols contained in…

mdag
- 129
- 1
- 4
12
votes
1 answer
Destructor of a global static variable in a shared library is not called on dlclose
In a main program, I dlopen and dlclose (LoadLibrary and FreeLibrary respectively) a shared library. The shared library contains a static variable that is instantiated upon dlopen, and destroyed upon dlclose. This behavior is consistent on MSVC 2008…

Infinity
- 363
- 2
- 12
12
votes
3 answers
What can cause dlopen: no suitable image found (can't map)?
What can cause the following error when loading an additional bundle using dlopen:
dlopen($(OBJ_DIR)/Test-20091217211256.ob, 6): no suitable image found. Did find:
$(OBJ_DIR)/Test-20091217211256.ob: can't map
Before this error, the process…

Tobias
- 6,388
- 4
- 39
- 64
11
votes
3 answers
typeinfo, shared libraries and dlopen() without RTLD_GLOBAL
I'm having some trouble with exceptions not functioning correctly (or at least, as I would hope; I know there are issues with this) across shared libraries when loaded using dlopen. I include some simplified example code here. The actual situation…

Brian O'Kennedy
- 1,721
- 1
- 13
- 18
11
votes
3 answers
dlopen and global variables in C/C++
Due to some restrictions I am being forced to load a library written in C at runtime. A third party provides two library to me as static archives which we turn into shared objects. The application I'm working with loads one of the libraries at…

mjn12
- 1,853
- 3
- 19
- 27
11
votes
1 answer
What is MODULE library type in cmake?
cmake add_library documentation says,
SHARED libraries are linked dynamically
and loaded at runtime. MODULE libraries are plugins that are not
linked into other targets but may be loaded dynamically at runtime
using dlopen-like…

sherlock
- 2,397
- 3
- 27
- 44
11
votes
1 answer
Get loaded address of a ELF binary, dlopen is not working as expected
I'm trying to get the loaded address of an ELF binary, but dlopen doesn't work as expected:
void *elf = (char *)dlopen (0, RTLD_NOW);
printf ("%p\n", elf);
sleep (100);
It prints 0xb772d918, but from what /proc/1510/maps tells, it doesn't point to…

daisy
- 22,498
- 29
- 129
- 265
10
votes
2 answers
Finding dylib version using dlopen
Is there a way to find the version of a dylib using its path? I am looking for something that accepts the same arguments as dlopen. I have looked at NSVersionOfRunTimeLibrary, but from my reading of the documentation it looks like it gets the…

adk
- 4,479
- 9
- 36
- 38
10
votes
1 answer
Can a Mac OS X application prevent dlopen from loading a library?
After some careful debugging, I have discovered a bug in my application that is rooted in the system frameworks loading a buggy Apple bundle:
/System/Library/CoreServices/MLTEFile.bundle
I am confident that I am not benefiting from the services of…

danielpunkass
- 17,527
- 4
- 24
- 38
9
votes
1 answer
C++: dlclose doesn't unload the shared library
I have a shared library loaded using dlopen (with the flags RTLD_NOW | RTLD_GLOBAL ).
If this library is using functions from the main program, then it does not unload. So I end up with the same code for this shared lib, even if I unloaded (using…

Ben
- 165
- 2
- 5
9
votes
2 answers
Undefined symbol when trying to load a library with dlopen
I'm trying to load a shared library (plugin) I was provided (closed source) with dlopen under a Linux ARM platform. I'm trying to load this way:
void* handle = dlopen(/, RTLD_NOW);
The result is a failure with this…

Luca Carlon
- 9,546
- 13
- 59
- 91
9
votes
2 answers
Is there a way to find out the number of references to a dynamic library in a process?
Is there a way to find out the number of references to a dynamic library in a process? i.e. in an application many modules might have loaded the same library using dlopen and when a module does dlclose, can we know if the library is really being…

Jay
- 24,173
- 25
- 93
- 141
9
votes
2 answers
Loading executable or executing a library
There is a large number of questions on SO about how to execute a library or dynamically load an executable. As far as I can tell, all the answers come down to: compile your executable as position-independent code and load it with dlopen. This…

foxcub
- 2,517
- 2
- 27
- 27
9
votes
1 answer
When we are supposed to use RTLD_DEEPBIND?
I was trying the issue mentioned at link: https://sourceware.org/ml/libc-alpha/2009-06/msg00168.html
I did some modification in the code as mentioned below:
>> Cat libdep.c
#include
int duplicate = 'u';
int get_duplicate() {
…

Ritesh
- 1,809
- 1
- 14
- 16