Monday, March 17, 2008

c/c++: dlclose

What should you know about dlclose? You should remember that it actually doesn't close the library. It decrements the reference counter. When the counter reaches zero value and no other libraries use symbols in it, then the library is unloaded. The next example will work:

    void *handle1 = dlopen("./obj", RTLD_LAZY);
    void *handle2 = dlopen("./obj", RTLD_LAZY);

    print p1 = (print)dlsym(handle1, "print");
    p1();
    dlclose(handle1);
    
    p1();

No comments: