Xcode: new build system - dyld: could not load inserted library libXCTestBundleInject.dylib
After updating to Xcode 11.4 unit testing is broken. Project builds successful, but when running the tests in the simulator the app crashes immediately with the following message
dyld: could not load inserted library '/Users/user/cmake_xcode_11_4/build/products/Debug-iphonesimulator/TestHost.app/Frameworks/libXCTestBundleInject.dylib' because image not found
After investigating a bit, it turned out that this is only the case if you run it with the "New Build System", if you use the "Legacy Build System" everything is fine.
Generated a sample project so it can be reproduced easily. cmake_xcode_11_4.zip Repro steps:
- Run
CMakeGenerate.sh
- Open build/cmake/HostProject.xcodeproj
- Run unit test for TestHost on any simulator -> should build and run without issues
- Go to Xcode File/Project Settings and change Build System to "New Build System"
- Rerun unit test for TestHost on any simulator -> error message appears
Problem appears to be that libXCTestBundleInject.dylib
is located in TestHost.app/PlugIns/Frameworks
instead of TestHost.app/Frameworks
.
Managed to fix the issue by resetting CONFIGURATION_BUILD_DIR
for the test to be the same as the host app's CONFIGURATION_BUILD_DIR
. This causes the dylib to be located in the right folder for xcode to look for.
Here's the previous state extended with the fix. cmake_xcode_11_4_fix.zip