Embedding or statically linking against a .dylib

Discussion in 'Mac Programming' started by Thomas Harte, Jan 26, 2006.

  1. macrumors 6502

    Joined:
    Nov 30, 2005
    #1
    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?
     
  2. macrumors 6502a

    csubear

    Joined:
    Aug 22, 2003
    #2
    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.
     
  3. thread starter macrumors 6502

    Joined:
    Nov 30, 2005
    #3
    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 (~ 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?
     
  4. macrumors 6502a

    csubear

    Joined:
    Aug 22, 2003
    #4
    work on my machine, 10.4.4. But core dumps when i exit the app.
     

Share This Page