I am writing a c++ command line tool for Mac OS 10.5+ with XCode 3.2.5 that is written like this :-
int main()
{
...
if (a == b)
{
doWork() // defined in my.dylib
doOtherWork() // defined in his.dylib
}
}
However it crashes even when a and b are not equal:-
Lab-Computer-9adf72:tmp labuser$ ./myapp
dyld: Library not loaded: ./my.dylib
Referenced from: /private/tmp/./myapp
Reason: image not found
Trace/BPT trap
Is there a way to make the app work at least when the functions are not called? Or make the loading happen only lazily?
There are multiple such functions being called from multiple dylibs so a per function check would be the last resort but even that would help.
I suppose that you load the library dynamically with
dlopen. You should then usedlsymto get the address of a symbol (function) by name. So you would do that:You can get more information here: Mac OS X ABI Dynamic Loader Reference.