I'm opening a dynamic library with a call to dlopen()
:
void *handle = dlopen("mylib.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle)
printf("%s", dlerror());
When this is called for a library which has an undefined symbol, the returned handle
is NULL and I get the following printed in TTY:
libmylib.so: undefined symbol: < the_symbol_name >
This is fine. But when I call this same code for the same library name for the second time, the returned handle
is NOT NULL, and I get a crash when dereferencing it.
From the docs:
If dlopen() fails for any reason, it returns NULL.
So why isn't NULL returned the second time?