Search code examples
xcodemacoscocoastatic-linkinglibavcodec

Xcode Cocoa app libav* and MagickWand static library issues


I've been developing a Cocoa app that uses both the libav* and ImageMagick C libraries but am having issues actually distributing the app. I have linked to the various static libraries in Xcode like so:

Xcode linking with libraries

The app builds and runs perfectly fine on my machine. Now I am trying to run it on a different computer. I archived the build, and exported it as a macOS app in Xcode, which leaves me with the .app archive. Now, when I try to run it on a different mac, I get the following error:

enter image description here

If I run otool -L binary_name on the built binary, I get a .dylib for every single one of the included .a files. I thought the whole point of a static library was that it gets built into main binary, and that there is then no need to do any dynamic linking. Why is it still trying to load the dylib?


Solution

  • I managed to resolve this issue, and believe it was due to the technical note listed here: Using static versions of existing dynamic libraries. Since the dependencies I am using were installed via homebrew, the lib folders of each dependency had both the .a and .dylib files, and Xcode was linking using the dylibs. To fix it, I copied all the .a files that I needed to a separate folder and adjusted my Library Search Paths in Xcode to point to the new folder. The app now builds and links to the static libraries as it should.