1

In my Xcode project, I have several dynamic libraries that I built with a prefix of "@rpath/lib". I added a "copy files" build phase that includes these dylibs. They are installed to a folder called lib in Frameworks. I also set a Runpath Search path of "@loader_path/../Frameworks" which should be substituted as @rpath when the executable runs. DLYD looks at my binary's runpath which I examine using tool -l command on the binary. This produces:

Load command 47
          cmd LC_RPATH
      cmdsize 40
         path @loader_path/../Frameworks (offset 12)

So I assume that when my binary runs, DLYD will resolve the path the lib folder via the MACH-O binary.

When I run my project, I use Activity Monitor to examine the files the binary has open. I don't see my dynamic libraries being referenced from @loaderpath/../Frameworks/lib where they reside, instead I see them being referenced from /usr/local/lib.

What Xcode settings do I set so my dynamic libraries are properly found? I used the User-Defined build setting 'DYLD_PRINT_BINDINGS' to see what is linking, and I don't see my libraries being linked even though they are eventually linked against the libraries in /usr/local/lib

blackirishman
  • 903
  • 1
  • 10
  • 23

1 Answers1

1

I have found the script I developed a while back which I used to copy .dylibs into the .app's Framework directory and detect dependent libraries, fixing the library references using install_name_tool. This should be set as a post-build script.

https://github.com/trojanfoe/xcodedevtools/blob/master/copy_dylibs.py

I haven't tested it for a while. The repo also contains the script I now use to bump build numbers, as per this question of mine.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I do have the dylibs in my "Embed Frameworks" General tab. I'm using FFmpeg libraries. When I build them using the --prefix option, the libraries and binaries are built into subfolders like bin and lib, hence my subfolder "lib". I could edit the path in the dylibs so that each ffmpeg dylib sees each other in the Framworks folder, but I still don't understand why my app keeps linking against /usr/local/lib when I don't have that specified in either Library Search Path or the RunTime Search Path. – blackirishman Feb 26 '19 at 14:27
  • 1
    @blackirishman This whole thing is a world of hurt as libraries generally have dependent libraries which should also be embedded into the `.app`. They can all go into `Frameworks` as long as their referenced name is changed using `install_name_tool` which should be run on each one. I spent 3 days once crafting a python script to do this for me and I might be able to fish that out. – trojanfoe Feb 26 '19 at 14:29
  • 1
    @blackirishman I have moved the script to github and updated and tested it last night. As well as starting with the target executable it also looks at the files that are already in `Frameworks` so it can be used along side Xcode's own *embed binaries* mechanism. You should put the libraries you want copied into `/usr/local` or `/opt/local` so it works well if you use Homebrew to supply your 3rd party libraries. – trojanfoe Feb 27 '19 at 07:00