POSIX function to dynamically load a library or binary into memory
Questions tagged [dlopen]
685 questions
19
votes
3 answers
Memory leak reported by valgrind in dlopen?
I've been debugging some app lately with valgrind, and I'm getting very weird reports from dlopen.
==1987== 32 bytes in 1 blocks are still reachable in loss record 1 of 2
==1987== at 0x4C24477: calloc (vg_replace_malloc.c:418)
==1987== by…

Anteru
- 19,042
- 12
- 77
- 121
18
votes
2 answers
Error loading psycopg2 module: Library not loaded: libpq.5.dylib
I am trying to run a Django project with Postgres database. I use Postgres 13.4 installed via postgressapp (UNIVERSAL with all currently supported versions) and python 3.9 (in venv). I work on Mac with Apple M1 chip, macOS Big Sur.
I faced the…

kokserek
- 530
- 8
- 21
18
votes
2 answers
library path when dynamically loaded?
How can I get the path of the shared library from within the library itself?
In other words, let's say that library X is loaded using dlopen(), how can I get access to the path that was used to load the said library from within the library…

jldupont
- 93,734
- 56
- 203
- 318
18
votes
1 answer
Cannot load any more object with static TLS
I have an application that use dlopen() to load additional modules. The application and modules are built on Ubuntu 12.04 x86_64 using gcc 4.6 but for i386 arch. The binaries are then copied to another machine with exactly same OS and work…

queen3
- 15,333
- 8
- 64
- 119
16
votes
2 answers
Get functions names in a shared library programmatically
Can I get list of all functions names from a shared library (Linux only) programmatically when I am using dl_open()?
I want something like this:
std::vector list_all_functions(void *dl) {
//... what can I do here?
}
int main() {
…

Alex Bar
- 841
- 2
- 9
- 18
14
votes
3 answers
using std::thread in a library loaded with dlopen leads to a sigsev
I recently discovered a strange behaviour using std::thread and dlopen.
Basically, when I execute a std::thread in a library which is loaded using dlopen I receive a sigsev. The library itself is linked against pthread, the executable that calls…

A. Gocht
- 143
- 1
- 7
14
votes
3 answers
How would a loaded library function call a symbol in the main application?
When loaded a shared library is opened via the function dlopen(), is there a way for it to call functions in main program?

Nikron
- 823
- 2
- 9
- 13
14
votes
2 answers
shared object can't find symbols in main binary, C++
I'm experimenting with making a kind of plugin architecture for a program I wrote, and at my first attempt I'm having a problem. Is it possible to access symbols from the main executable from within the shared object? I thought the following would…

cheshirekow
- 4,797
- 6
- 43
- 47
14
votes
2 answers
Casting when using dlsym()
I'm using dlsym() in C and I have a question whether the return value of dlsym() should be explicitly cast or if it is implicitly cast correctly. Here is the function:
double (*(compile)(void))(double x, double y)
{
if (system("scan-build clang…

lord.garbage
- 5,884
- 5
- 36
- 55
14
votes
1 answer
Error: dlopen() Library not loaded Reason: image not found
I am a newbie in this field. My laptop is Macbook air, Software: OS X 10.8.5 (12F45). I am running a code which gives me the following error:
dlopen(/Users/ramesh/offline/build_icerec/lib/icecube/phys_services.so, 2): Library not loaded:…

Ramesh
- 143
- 1
- 1
- 6
14
votes
5 answers
Using dlopen, how can I cope with changes to the library file I have loaded?
I have a program written in C++ which uses dlopen to load a dynamic library (Linux, i386, .so). When the library file is subsequently modified, my program tends to crash. This is understandable, since presumably the file is simply mapped into…

kdt
- 27,905
- 33
- 92
- 139
13
votes
2 answers
how to call function in executable from my library?
I have an executable and a dynamic library (.so). The library exports some symbols and executable calls it successfully. But I want to make possible to library call executable's functions. I've tried to do following in executable:
//test
extern "C"…

milo
- 1,220
- 3
- 17
- 33
13
votes
4 answers
dynamic_cast fails when used with dlopen/dlsym
Intro
Let me apologise upfront for the long question. It is as short as I could make it, which is, unfortunately, not very short.
Setup
I have defined two interfaces, A and B:
class A // An interface
{
public:
virtual ~A() {}
virtual void…

Kees-Jan
- 518
- 4
- 16
13
votes
3 answers
linux dlopen: can a library be "notified" when it is loaded?
Is there a way for a shared library to be "notified" when it is loaded?
In other words, let's say I use dlopen on a shared library, is there a function that is automatically called (if present) on the shared library (e.g. main?)

jldupont
- 93,734
- 56
- 203
- 318
12
votes
2 answers
dlopen() search path
is there a way to find out programmatically which paths are searched by dlopen() for shared objects? I always thought dlopen() would only look in /lib and /usr/lib but now I've seen that on Linux Mint several core components like libglib-2.0.so are…

user1055225
- 123
- 1
- 1
- 4