I have a main application that dynamically loads dylib , from inside that dylib I would like to call exported functions from my main program. I use dlopen(NULL,flag) to retrieve the main applications handle and dlsym(handle, symbol) to get the function .
dlopen gives no error , but when I try dlsym my function , I get the following error :
dlerror dlsym(RTLD_NEXT, CallMe): symbol not found
The symbol is exported with a correction confirmed by nm. I'm not sure why RTLD_NEXT is RTLD_NEXT ? Is this the result of dlopen(NULL,flag) ?
How can I solve this problem or achieve my goal?
Or are there other ways to invoke the main application (preferably without passing function pointers to dylib)?
Thanks in advance!
Added:
Export
extern "C" { void CallMe(char* test); } __attribute__((visibility("default"))) void CallMe(char* test) { NSLog(@"CallMe with: %s",test); }
Result nm
... 0000000000001922 T _CallMe ..
Code in dylib:
void * m_Handle; typedef void CallMe(char* test); CallMe* m_Function; m_Handle = dlopen(NULL,RTLD_LAZY); //Also tried RTLD_NOW|RTLD_GLOBAL if(!m_Handle) return EC_ERROR; m_Function = (CallMe*)dlsym(m_Handle, "CallMe"); if(!m_Function) return EC_ERROR; m_Function("Hallo");
source share