I have a pretty complex project built on macOS. It uses IMPORTED shared libraries, as well as internal ones. The dependency graph is pretty big, but basically, the internal dylibs are depending on the imported ones and on each other, the executables are depending on imported and built libraries.
CMAKE_MACOSX_RPATH is set to TRUE, and the executables have LC_RPATH entries with all the directories of the dependencies, either in the build tree for targets of the project, or on the host for IMPORTED ones. So far so good, the executables can be started directly from the build tree.
Now comes the issue: we just consolidated the dependencies in the project: removing outdated ones, adding explicit ones where required, moving them between PUBLIC and PRIVATE as required… After this refactoring, the LC_RPATH is not set on the executables anymore. I could trace the issue down to build.ninja.
LINK_LIBRARIES = -Wl,-rpath,/path/of/a -Wl,-rpath,/path/of/b -Wl,-rpath,/path/of/imported.dylib lib/a.dylib lib/b.dylib /path/of/imported.dylib -framework Cocoa …
LINK_LIBRARIES = lib/a.dylib lib/b.dylib /path/of/imported.dylib -framework Cocoa …
Note that the “-Wl,-rpath” are now missing. Not only those for the transitive dependencies, also for direct ones.
I do not understand why. We did not change the RPATH options, just the dependency tree. The dependencies are still correct, because the executables can be linked. Only the LC_RPATH are missing, leading to a runtime error:
dyld: Library not loaded: @rpath/a.dylib Referenced from: /path/to/build/tree/bin/excutable Reason: image not found
One of the executable is defined in its own sub-project(). I removed the project() statement as an experiment, and then the LC_RPATH was set again. I do not understand that either. It would be a workaround, but I would prefer a proper fix.
Any hint would be appreciated…