POSIX function to dynamically load a library or binary into memory
Questions tagged [dlopen]
685 questions
9
votes
2 answers
dlopen with two shared libraries, exporting symbols
I have a linux shared library, foo.so, which is loaded from an executable using dlopen("foo.so", RTLD_NOW | RTLD_LOCAL). From foo.so I'd like to dlopen another library, bar.so, which references symbols defined in foo.so, but the linker fails to find…

mr grumpy
- 1,513
- 1
- 10
- 17
9
votes
1 answer
python c extension, problems with dlopen on mac os
I've taken a library that is distributed as a binary lib (.a) and header, written some c++ code against it, and want to wrap the results up in a python module.
I've done this here.
The problem is that when importing this module on Mac OSX (I've…

Jason Sundram
- 12,225
- 19
- 71
- 86
9
votes
1 answer
Dynamic Loading Without extern "C"
I'd like to use libdl to dynamically load C++ in general. The problem is identifying symbols at runtime that have been name mangled.
As described here, one solution is to remove name mangling by using extern…

Praxeolitic
- 22,455
- 16
- 75
- 126
9
votes
1 answer
dlopen vs linking overhead
Suppose I have a library - foo.so . When building my binary (which needs this library), I can either (1) link foo.so , or, (2) within the program source code, dlopen this library and then call functions provided by this library
Is there any…

MK.
- 3,907
- 5
- 34
- 46
8
votes
3 answers
dlopen() error image not found
I have software that first loads a .dylib lets call libFirst.dylib using the following command:
void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
Later on inside a function from the loaded libFirst.dylib I attempt to load another .dylib…

Michael Wildermuth
- 5,762
- 3
- 29
- 48
8
votes
1 answer
What is the usecase of RTLD_LAZY and RTLD_NOW in code
How can I differentiate between RTLD_LAZY and RTLD_NOW and when to use what in code?

wasnaz
- 89
- 1
- 2
8
votes
2 answers
overriding @executable_path in a DLL loaded with dlopen()
Operating system is MacOS X, specifically 10.5 (Leopard) on a PowerPC G4, but I have the same problem on an x86 running 10.6.
I am writing an application which dynamically loads a DLL. The DLL (let's call it foo.dylib) is part of another…

Thomas Pornin
- 72,986
- 14
- 147
- 189
8
votes
3 answers
LD_PRELOAD doesn't affect dlopen() with RTLD_NOW
If I use a function from a shared library directly, i.e. by declaring it in my code and linking during compile time, LD_PRELOAD works fine. But if I use dlopen()/dlsym() instead LD_PRELOAD has no effect!
The problem is that I want to debug a program…

sashoalm
- 75,001
- 122
- 434
- 781
8
votes
1 answer
dlopen doesn't respect `RTLD_LOCAL`?
I have A.so, which links to a particular versioned libstdc++.so.6 at its own directory (via rpath set to $ORIGIN).
If I dlopen A.so alone, it works fine.
If I dlopen my system's libstdc++.so.6 (which is of different version) in RTLD_LOCAL mode, and…

colinfang
- 20,909
- 19
- 90
- 173
8
votes
1 answer
How to do runtime binding based on CPU capabilities on linux
Is it possible to have a linux library (e.g. "libloader.so") load another library to resolve any external symbols?
I've got a whole bunch of code that gets conditionally compiled for the SIMD level to be supported ( SSE2, AVX, AVX2 ). This works…

Mark Borgerding
- 8,117
- 4
- 30
- 51
8
votes
1 answer
Main Program and Shared Library initializes same static variable in __static_initialization_and_destruction_0
Does anyone know why a library initialized within dlopen() would initialize a static variable owned by the main program. Both the main program and shared library have a copy of the static variable, but for some reason the shared library…

Paul
- 317
- 3
- 11
8
votes
1 answer
dlopen a dynamic library from a static library, when the dynamic library uses symbols of the static one
This question is closely related to dlopen a dynamic library from a static library linux C++, but contains a further complication (and uses C++ instead of C):
I have an application that links against a static library (.a) and that library uses the…

Johanna
- 195
- 1
- 10
8
votes
3 answers
Creating a static C struct containing strings
I'm trying to create a dynamic library in Rust that exports a struct as a symbol that will be loaded into a C program via dlopen().
However, I'm was running into some segfaults when accessing the second string in the struct, so I made a small test…

chrippa
- 83
- 4
8
votes
1 answer
When exactly is gcc __attribute__((constructor)) run?
Let's say I have an libA.so with GCC constructor.
My program "program" depends on libA.so, so when I run it, libA.so gets opened and its constructor is executed. Now, I also have a module, libC.so, which also depends on libA. I run…

che
- 12,097
- 7
- 42
- 71
8
votes
1 answer
Potential reasons dlopen could segfault?
What are some of the reasons dlopen could segfault besides the shared object not existing?
In my case, I know the shared object exists, but when my program goes to load it using dlopen, it segfaults. I checked in my lib folder and the shared object…

user1496542
- 539
- 2
- 6
- 14