POSIX function to dynamically load a library or binary into memory
Questions tagged [dlopen]
685 questions
83
votes
10 answers
MatLab error: cannot open with static TLS
Since a couple of days, I constantly receive the same error while using MATLAB which happens at some point with dlopen. I am pretty new to MATLAB, and that is why I don't know what to do. Google doesn't seem to be helping me either. When I try to…

Hans Meyer
- 931
- 1
- 7
- 4
56
votes
3 answers
building a .so that is also an executable
So everyone probably knows that glibc's /lib/libc.so.6 can be executed in the shell like a normal executable in which cases it prints its version information and exits. This is done via defining an entry point in the .so. For some cases it could be…

user175104
- 3,598
- 2
- 23
- 20
55
votes
4 answers
Multiple instances of singleton across shared libraries on Linux
My question, as the title mentioned, is obvious, and I describe the scenario in details.
There is a class named singleton implemented by singleton pattern as following, in file singleton.h:
/*
* singleton.h
*
* Created on: 2011-12-24
* …

bourneli
- 2,172
- 4
- 24
- 40
51
votes
4 answers
Automatically executed functions when loading shared libraries
When loading shared libraries in Windows, LoadLibrary() call causes DllMain in library to execute for each new process and thread library attaches to, and for each process and thread library deattaches from.
Is there similar mechanism for Mac OS X,…

toriningen
- 7,196
- 3
- 46
- 68
38
votes
9 answers
dlopen from memory?
I'm looking for a way to load generated object code directly from memory.
I understand that if I write it to a file, I can call dlopen to dynamically load its symbols and link them. However, this seems a bit of a roundabout way, considering that it…

Jeremy Salwen
- 8,061
- 5
- 50
- 73
27
votes
7 answers
How to correctly assign a pointer returned by dlsym into a variable of function pointer type?
I am trying to use dlopen() and dlsym() in my code and compile it with gcc.
Here is the first file.
/* main.c */
#include
int main()
{
void *handle = dlopen("./foo.so", RTLD_NOW);
if (handle) {
void (*func)() =…

Lone Learner
- 18,088
- 20
- 102
- 200
26
votes
6 answers
dlclose doesn't really unload shared object, no matter how many times it is called
My program uses dlopen to load a shared object and later dlclose to unload it. Sometimes this shared object is loaded once again. I noticed static variables are not re-initialized (something which is crucial to my program) so I added a test (dlopen…

Elektito
- 3,863
- 8
- 42
- 72
23
votes
1 answer
Is the function 'dlopen()' private API?
I want use function 'dlopen()' to invoke a dynamic library on iOS platform, is the function 'dlopen()' private API?

Donald
- 321
- 1
- 2
- 10
23
votes
3 answers
Receive "undefined symbol" error when loading library with dlopen
I'm writing some code that uses dynamic shared libraries as plugins.
My command line for building the shared libraries looks like:
cc -shared -fPIC -o module.so -g -Wall module.c
Within the module, I can call functions that are in any other shared…

Alnitak
- 334,560
- 70
- 407
- 495
23
votes
1 answer
dlclose() does not call the destructor of global objects
plugin1.cpp:
#include
static class TestStatic {
public:
TestStatic() {
std::cout << "TestStatic create" << std::endl;
}
~TestStatic() {
std::cout << "TestStatic destroy" << std::endl;
}
} test_static;
host.cpp
#include…

AndryBlack
- 233
- 2
- 6
23
votes
1 answer
Difference between linking OpenMP with -fopenmp and -lgomp
I've been struggling a weird problem the last few days. We create some libraries using GCC 4.8 which link some of their dependencies statically - eg. log4cplus or boost. For these libraries we have created Python bindings using boost-python.
Every…

duselbaer
- 935
- 2
- 6
- 10
21
votes
4 answers
Using dlopen() on an executable
I need to call a function from another program. If the other program were a library, I could simply use dlopen and dlsym to get a handle to the function. Unfortunately, the other program is a Unix Executable, and building it as a library is not an…

Jeff
- 2,149
- 3
- 17
- 19
20
votes
3 answers
What is causing sprof to complain about "inconsistency detected by ld.so"?
I'm trying to use sprof to profile some software (ossim) where almost all the code is in a shared library. I've generated a profiling file, but when I run sprof, I get the following error:
> sprof /home/eca7215/usr/lib/libossim.so.1…

Edward
- 1,786
- 1
- 15
- 33
19
votes
5 answers
Returning a shared library symbol table
For instance:
void* sdl_library = dlopen("libSDL.so", RTLD_LAZY);
void* initializer = dlsym(sdl_library,"SDL_Init");
Assuming no errors, initializer will point to the function SD_Init in the shared library libSDK.so.
However this requires knowing…

joemoe
- 5,734
- 10
- 43
- 60
19
votes
2 answers
OSX 10.7.5 - Ruby on Rails LoadError: Could not open library 'sodium': dlopen(sodium, 5)
After typing rake db:create i get:
LoadError: Could not open library 'sodium': dlopen(sodium, 5): image not found.
Could not open library 'libsodium.dylib': dlopen(libsodium.dylib, 5): image not found
Here's some more…

Python Lord
- 341
- 2
- 4
- 15