Dynamic loading of a third party .dylib
Dynamic loading of a third party .dylib
- Subject: Dynamic loading of a third party .dylib
- From: "email@hidden" <email@hidden>
- Date: Sat, 7 Aug 2010 23:44:47 +0100
My Cocoa app would very much like to link to a third party dylib.
The dylib is created using an external make file and I don't really want to start modifying the build script to change the deployment INSTALL_PATH.
I know that I can wield install_name_tool in a build phase but I thought about using dlopen().
I know where my dylib is in my bundle so I can target it okay.
1. In Xcode I link to my dylib and mark it as weak.
2. In my app I call dlopen() before accessing any of the library symbols.
But the symbol doesn't get resolved.
The crash log reports:
Dyld Error Message:
can't resolve symbol _G__main in /Nuzzle/And/Scratch/MacOS/Contents/boo because dependent dylib #5 could not be loaded
Do I have to manually call dlsym() or am I missing a weak attribute somewhere.
Or am I just lost in the weeds.
some code:
NSString *dylibPath = [path stringByAppendingPathComponent:@"lib/libCint.dylib"];
const char *libPath = [dylibPath cStringUsingEncoding:NSUTF8StringEncoding];
void *dl = dlopen(libPath, RTLD_NOW);
const char *dlErr = dlerror();
if (dlErr) {
NSLog(@"dlerror() = %s", dlErr);
} else {
NSLog(@"dylib path is %s, dl = %p", libPath, dl);
}
G__main(0, NULL); // in libCint.dylib
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden