How to avoid loading dynamic libraries on other machine in C++ project (XCode)?


I'm creating C++ Unity plugin in Xcode with OpenCV for OS X. The plugin compiles and works on my Mac, but on other machines it tries to load dynamic libraries (for example, ffmpeg, libtiff, webp) from /usr/local/opt... (Library not loaded: /usr/local/opt/webp/lib/libwebp.6.dylib etc.)

Brew install solves the problem, but it is necessary to distribute this plugin "as is".

I have 2 questions: 1) how can I know if my project will try to use dynamic libraries (on other machine)?

2) how can I make my project to load them from bundle, not from /usr/local/opt? (I tried link with -static, but there were 136 errors "Undefined symbols for architecture x86_64 - _OSSpinLockLock, _dispatch_get_global_queue and many others).

Show source
| xcode   | c++   | dylib   | opencv   | osx   2016-11-11 22:11 1 Answers

Answers ( 1 )

  1. 2016-11-11 23:11

    I am not sure how to answer your first question... if you don't know what libraries your project links to who does?

    For the second question. You need to set the 'install name' of the dynamic library. You will easily find detailed information about it and about the install_name_tool command line that can be used to manipulate it, but essentially it is a variable engraved inside the .dylib itself that stores a path. That path tells the binary which links to it where to find it. When you bundle the dylib in your deployable, your install name is often set to something like @executable_path/path/relative/to/executable/. The install name is either set when you compile the library as a compiler flag, or can be set later on using install_name_tool on the dylib file.

    Notice also the 'Runpath Search Path' option in Xcode Build Settings which is connected to this.

    I hope this is enough to point you to the direction you need.

◀ Go back