1

I have a problem with a dynamic library in a Cocoa application.

On a button action, I load a dylib, resolv a function in it and executes it, like the following :

void* handle = dlopen("blah.dylib", RTLD_LAZY);
if (!handle)
{
    NSLog(@"dlopen() failure : %s", dlerror());
    return;
}

function_to_resolv p = (function_to_resolv)dlsym(handle, "function_to_resolv");
function_to_resolv();
if (dlclose(handle) != 0)
    NSLog(@"FAIL");

All works fine, except that the library is never unloaded from the binary.

I verified it with the following code :

const uint32_t s = _dyld_image_count();
for (uint32_t i = 0; i < s; i++)
{
    const char* str = _dyld_get_image_name(i);
    NSLog(@"%s", str);
}

Why could be the reason of this ?

Nyx0uf
  • 4,609
  • 1
  • 25
  • 26
  • 1
    Maybe http://stackoverflow.com/questions/8793099/unload-dynamic-library-needs-two-dlclose-calls provides the answer. – Matthias Mar 01 '12 at 16:06
  • Gosh, I missed that. Thanks that resumes exactly the problem, but sadly there is no solution atm :( – Nyx0uf Mar 01 '12 at 21:52

1 Answers1

0

The thread Matthias Werner linked contains useful informations : unload dynamic library needs two dlclose() calls?

This behavior is because of the Obj-c runtime, and there is nothing to be done at the moment.

Community
  • 1
  • 1
Nyx0uf
  • 4,609
  • 1
  • 25
  • 26