'Xcode new build system problem with circular dependency on framework and dylib not found by executable
My project is an Objective-C application that loads a chosen dylib as a "plug-in" at runtime; both the application and the "plug-in" use a framework that is written in C++ as is the "plug-in". The C++ components are platform-independent; e.g. the 'plugin" is loaded via the Unix delfcn.h facility. For many years, I had this set up in Xcode with no problems, but under the new build system it breaks in several ways. I'll try to summarize the setup that works under the legacy build system.
The main project has two targets: one is the Objective-C application, and the other is the C++ framework. The framework appears as both a framework used by the application, and one of the products. Xcode always builds the framework first before the application. A post-build phase copies the framework to ~/Library/Frameworks, but the original is left in place in the Build directory. The "plug-in" project is a separate Xcode project that includes the framework, and produces a dylib product. The application loads the plugin using the Unix dlfcn.h functions. All this has worked great when built with the legacy Xcode build system.
The problems under the new build system are first, that circular dependencies appear in the main project because the framework appears both as an input to the application target and as a product that needs to be built as a second target. It builds the framework first, but then reports the dependency error. Splitting the main project into two and manually building the framework first solved that problem. However I was able to get the two-target project to work in the new build system by specifying the dependences explicitly and substituted a run script for the post-build copy operation. This works fine if I execute the application from within Xcode.
However, the second problem is that if I launch the built application executable directly, it crashes, unlike before, with a message that the framework dylib cannot be found although the path listed in the crash message appears to be an exact match for the actual framework location. The "plug-in" project appears to build and get loaded just fine, which suggests that the framework (which it uses) is properly built and stored.
I've concluded that either the new build system has some bugs or subtle options somewhere I have to choose, or I am simply not understanding something fundamental.
Any suggestions on how I might proceed to sort this out? I've seen other postings of similar problems with the new build system, but they seem to be very specific to e.g. Cocaopods. I'm happy to study documentation, but there doesn't seem to be much about setting up and using a framework in this way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
