5

I'm using OS X 10.7 (Lion), XCode 4.6.3 and libstdc++ as the C++ Standard Library.

I have this code in my main project:

shared.cpp:

extern "C" int sharedFun()
{
    return 5;
}

And this in my side project, that needs to dynamically load the main one:

loader.cpp:

#include <dlfcn.h>

int main(int argc, const char * argv[])
{
    void* mainApp = dlopen("mainApp.dylib", RTLD_LAZY);

    char* error;
    dlsym(mainApp, "sharedFun");

    if ((error = dlerror()) != nullptr)
    {
         ....
    }
}

nm output:

nm -gU mainApp.dylib | grep sharedFun
002a3a10 - 01 0000   FUN _sharedFun
002a3a10 T _sharedFun

dlopen loads the library just fine, but dlsym returns "symbol not found". Any ideas?

Thanks.

Tsury
  • 729
  • 1
  • 9
  • 24

0 Answers0