POSIX function to dynamically load a library or binary into memory
Questions tagged [dlopen]
685 questions
7
votes
1 answer
C++: implementation of a class methods in a separated shared library
I figure out I can have the implementation of parts of a class in a shared lib, as far as the symbols are loaded when used.
myclass.h
---
class C {
void method();
}
main.cpp
---
#include "myclass.h"
int main() {
//dynamically load mylib.so…

Ben
- 165
- 2
- 5
7
votes
1 answer
How to intercept file system access inside dlopen()?
I want to intercept all file system access that occurs inside of dlopen(). At first, it would seem like LD_PRELOAD or -Wl,-wrap, would be viable solutions, but I have had trouble making them work due to some technical reasons:
ld.so has already…

Jed
- 1,651
- 17
- 26
7
votes
2 answers
How can a Solaris process read its own symbol table?
I have a Solaris process, which is a C++ application that is loaded by ld with a few .so libraries. This application has a function that gets a return address in the calling function and then tries to determine the name of the said calling…

evolvah
- 625
- 4
- 15
7
votes
3 answers
Unable to load dynamic library(DYLIB) in MacOS
I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String…

Ramkumar
- 444
- 1
- 7
- 22
7
votes
1 answer
In what order are shared libraries initialized and finalized?
The dynamic objects in a process come from several sources:
The executable itself
Any libraries it requires (DT_NEEDED for ELF)
Libraries loaded explicitly (dlopen or similar)
Any libraries required by such explicit loads
They can be unloaded…

Davis Herring
- 36,443
- 4
- 48
- 76
7
votes
1 answer
Why does this dynamic library loading code work with gcc?
Background:
I've found myself with the unenviable task of porting a C++ GNU/Linux application over to Windows. One of the things this application does is search for shared libraries on specific paths and then loads classes out of them dynamically…

bckohan
- 203
- 1
- 6
7
votes
1 answer
How does the dlsym work?
it's very easy to find how to use dlsym() and other functions from this family, but how does it work internally? Is it possible to write own, easy implementation of dlsym()?
I'm wondering if it is possible to achieve similar behavior but without…

kashpersky
- 165
- 2
- 8
7
votes
2 answers
Debugging a crash when a library is opened via dlopen on OSX
I have a problem with a C++ application I've developed which uses dlopen to load user-developed libraries. The application has been used by a variety of people on a variety of linux distros and versions of OSX over the last couple of years and so…

Nick Hawes
- 317
- 2
- 14
7
votes
1 answer
Does dlopen re-load already loaded dependencies? If so, what are the implications?
I have a program, code-named foo. foo depends on common.so and is linked to it in the normal way (sorry I don't know the technical way to say that). When foo is running it then dynamically loads bar.so using dlopen(). So far so good.
But, bar.so…

Gyan aka Gary Buyn
- 12,242
- 2
- 23
- 26
7
votes
1 answer
dlclose does not close library open file handles
I am dynamically loading a library with dlopen, then closing it with dlclose. I expected all library resources to be freed once dlclose completed, but there are still open file descriptors from the library after the dlclose call. I am wondering how…

Daniel Kats
- 5,141
- 15
- 65
- 102
7
votes
2 answers
How to compile ELF binary so that it can be loaded as dynamic library?
This is theoretical question. I am aware that perhaps best practice would be the use of shared libraries. But I ran into this question and cannot seem to find an answer anywhere.
How to construct the code and compile in ELF format a program in C/C++…

Alexey Kamenskiy
- 2,888
- 5
- 36
- 56
7
votes
1 answer
How to programmatically list ELF shared library symbols
In my C shared library, I want to dlopen() another shared library and retrieve a list of the exported symbols this library has.
Is there a way I can do that programmatically, without running nm/objdump?
As a secondary question: How can I retrieve…

linker
- 71
- 3
7
votes
1 answer
Use dlsym on a static binary
Is there any hope of running dlopen(NULL, ...) and getting symbols for a statically compiled binary?
For example, with the following code I can get symbols if the program is compiled dynamically and I use -rdynamic.
$ gcc -o foo foo.c -ldl…

bfroehle
- 1,116
- 10
- 12
7
votes
2 answers
dlopen - Undefined symbol error
I'm using dlopen to load a shared library at run time
dlopen("SharedLibarary1.so", RTLD_NOW | RTLD_GLOBAL);
In that shared object I refer to a const char* defined in another shared library "SharedLibarary2.so".
The Executable, and both the…

Sak
- 269
- 1
- 4
- 13
7
votes
1 answer
Is there a way for dlopen to reload a dylib file on iOS?
As the title says... I'm interested in dlopen(). I understand this isn't allowed by the app store but I'm curious about this on iOS.
The issue I have is that I can create a .dylib file and I can load this file at runtime with the following code
char…

Eamonn Moloney
- 487
- 4
- 12