PDA

View Full Version : Embedding or statically linking against a .dylib




Thomas Harte
Jan 26, 2006, 10:08 AM
I am using XCode 2.2. I have a .dylib that corresponds to a library I have downloaded from the internet and built myself. I wish to be able to release my program without requiring users to download and build the library. I therefore wish to either embed the .dylib or statically link against it. How would I achieve this?



csubear
Jan 26, 2006, 10:27 AM
Ah yes the joys of deployment.

What you want to do is have the dylib live in your bundle. Some people create a plug-in folder for it others just put it in your resouce directory. I'm lazy and just put it in the resource directory.

You also need to change the dylib's internal pathing. You can view this with the command otool -L yourlib.dylib at the terminal, and you can change the internal pathing with the command install_name_tool. It should be something like

install_name_tool -id @executable_path/../Resources/yourlib.dylib youlib.dylib


hope this helps.

Thomas Harte
Jan 26, 2006, 07:44 PM
Okay, I have used install_name_tool in the way that you recommend and in XCode I have added a custom "Copy Files" build phase that copies the dylib to my Resources. Using otool on the binary in my application bundle reveals that it is now looking for @executable_path/<etc>, and checking my bundle reveals that my dylib does now turn up in the right place.

I therefore hope that I can just deploy the output of XCode without doing anything at the command line. I guess I'll find out!

EDIT: if anybody feels like testing, then I've uploaded to here (http://members.allegro.cc/ThomasHarte/osx/files/b-em/B-Em10.dmg) (~ 956 kB). It "should" be compatible with 10.2 and above, but I've only tested on 10.4. It's an OS X port of a BBC Micro emulator by Tom Walker, with native menus and so on. It runs kind of slow because of some of the libraries it depends upon but anything 1 Ghz ish should run the emulator at full speed. The real question is: does it load up and run?

csubear
Jan 26, 2006, 09:30 PM
work on my machine, 10.4.4. But core dumps when i exit the app.