How to properly set run paths, search paths, and install names?

前端 未结 2 1105
不思量自难忘°
不思量自难忘° 2020-12-25 15:36

I have a collection of projects that I\'m compiling as dynamic libraries. Each of these .dylibs depend on other various .dylibs that I would like to place in various other d

2条回答
  •  隐瞒了意图╮
    2020-12-25 15:51

    Typically, in my dylib's target, I set INSTALL_PATH aka "Installation Directory" to the prefix I want (e.g. @executable_path/../Frameworks).

    I leave LD_DYLIB_INSTALL_NAME aka "Dynamic Library Install Name" set to its default value, which is $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH).

    Xcode expands that based on your target's name, so it might end up being @executable_path/../Frameworks/MyFramework.framework/Versions/A/MyFramework, for instance.

    The important thing to realize is that the install path is built into the dylib, as part of its build process. Later on, when you link B.dylib that refers to A.dylib, A.dylib's install path is copied into B.dylib. (That's what otool is showing you -- those copied install paths.) So it's best to get the correct install path built into the dylib in the first place.

    Before trying to get all the dylibs working together, check each one individually. Build it, then otool -L on the built dylib. The first line for each architecture should be what LD_DYLIB_INSTALL_NAME was showing you.

    Once you have that organized, try to get the dylibs linking against each other. It should be much more straightforward.

提交回复
热议问题