1

I want to distribute some libraries in to my OS X application bundle, last two days i am working on this however couldn't make it. until now what i did.

with using install name tool i have fixed library paths. additionally in time i have tried @loader_path/../Libraries and @executable_path/../Libraries as well.

otool -L libMagickWand-6.Q16.2.dylib 
@rpath/../Libraries/libMagickWand-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
    @rpath/../Libraries/libMagickCore-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
    @rpath/../Libraries/libfreetype.6.dylib (compatibility version 18.0.0, current version 18.2.0)
    @rpath/../Libraries/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    @rpath/../Libraries/libz.1.2.5.dylib (compatibility version 1.0.0, current version 1.2.5)
    @rpath/../Libraries/libltdl.7.dylib (compatibility version 11.0.0, current version 11.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

in project targets / Build Phases / Add New Build Phase / Add Copy Files build Phase and copied all dynamic libraries to my app bundle.

enter image description here

that worked well, I can see the libraries are in the app bundle.

enter image description here

then adding @rpath/../Libraries/ to Build Settings / Runpath Search Paths

enter image description here

but still getting error message..

ld: library not found for -lMagickWand-6.Q16.2 clang: error: linker command failed with exit code 1 (use -v to see invocation)

if i add direct path lets say libraries are located in /User/username/libs/ to Library Search Paths in build settings it works.

enter image description here

am i missing something?

modusCell
  • 13,151
  • 9
  • 53
  • 80

1 Answers1

3

Content/Libraries is not a standard directory within an app bundle; use Contents/Frameworks instead (.dylibs are allowed in that directory just the same as .frameworks).

Set the Install Name of each library to @rpath/libWhatever.dylib and set the Runpath Search Path of the executable (in Contents/MacOS) to @loader_path/../Frameworks.

For library interdependencies then Runpath Search Path will need to be simply @loader_path so dependent libraries can be loaded from the same directory.

EDIT: People might find the copy_dylibs.py script in this repo useful for copying third-party .dylibs into the App Bundle. It recursively hunts for libraries that need copying and corrects the Install Name of the libraries as well as code-signing them.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • do you mean a library it self path should be @rpath/libMagickCore-6.Q16.2.dylib and for the same library dependencies path should be like this @loader_path/../Frameworks/a.dependency.dylib? i am sorry little bit confused. – modusCell May 17 '14 at 14:21
  • 1
    @mohacs The *Install Name* of all libraries should be `@rpath/$(EXECUTABLE_PATH)` when being built within Xcode or `@rpath/libWhatever.dylib` when being changed with `install_name_tool`. Think of `@rpath` as being the same as `$PATH` is for executables on the command line; it simply tells the loader where to find libraries it's looking for. – trojanfoe May 17 '14 at 14:27
  • thank you, now basically it is not throwing error to say library not found (no test machine libraries are not there) however even on development machine when i put @loader_path/../Frameworks to runpath search paths invoking any library methods does nothing. if i remove run path and add library paths to regular library search paths it works. still i am missing something. should i always keep regular library search path /Users/username/Desktop/lib2. otherwise it won't compile. do i need add a flag or something like that? – modusCell May 17 '14 at 17:38
  • ok, your solution is %100 correct it did not worked at the first place but i figured out there were problems on libraries which i previously compiled. recompiled the libraries and worked like a charm. all libs placed to ../Frameworks and the app work on every computer. thank again. – modusCell May 17 '14 at 21:28
  • 1
    Top in answer where it says `Content/Frameworks`? Al of Apple's docs refer to `Contents/Frameworks`. – Arch D. Robison Nov 24 '15 at 23:06
  • @trojanfoe, What would you do in this case: http://stackoverflow.com/questions/40318465/setting-the-search-path-for-plug-in-dylib ? Thank You. – Royi Oct 29 '16 at 11:11