Carthage: Unit test target: Library not loaded: @rpath…

Created on 11 May 2016  ·  6Comments  ·  Source: Carthage/Carthage

I'm unable to get a unit test target to load frameworks built with Carthage. The app starts but crashes. Output is below.

I've checked out the readme about testing, the instructions on issue #615, and the article here (As well as several other issues)

NOTE: I have successfully integrated 3 libraries into the app target, and those work great. I can launch the app and it runs. The only issue is with the test target.

I have posts a pull request with all the changes. You can see the project settings here:
https://github.com/wikimedia/wikipedia-ios/pull/695

Any ideas on what I haven't done to get this working properly?

Thanks

Output on launch

2016-05-11 16:11:49.727 Wikipedia Debug[73603:2217984] Failed to load test bundle from file:///Users/cfloyd/Library/Developer/Xcode/DerivedData/Wikipedia-dmetuhvbstfjrbabxuxgmyuakopg/Build/Products/Debug-iphonesimulator/Wikipedia%20Debug.app/PlugIns/WikipediaUnitTests.xctest/../WikipediaUnitTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/Users/cfloyd/Library/Developer/Xcode/DerivedData/Wikipedia-dmetuhvbstfjrbabxuxgmyuakopg/Build/Products/Debug-iphonesimulator/Wikipedia Debug.app/PlugIns/WikipediaUnitTests.xctest/WikipediaUnitTests): Library not loaded: @rpath/FBSnapshotTestCase.framework/FBSnapshotTestCase
  Referenced from: /Users/cfloyd/Library/Developer/Xcode/DerivedData/Wikipedia-dmetuhvbstfjrbabxuxgmyuakopg/Build/Products/Debug-iphonesimulator/Wikipedia Debug.app/PlugIns/WikipediaUnitTests.xctest/WikipediaUnitTests
  Reason: image not found"

The steps I have taken.

  • carthage version: 0.12
  • xcodebuild -version: Xcode 7.3.1 Build version 7D1014
  • Are you using --no-build? No
  • Are you using --no-use-binaries? No
  • Are you using --use-submodules? No

Cartfile

# Release Libraries
github "CocoaLumberjack/CocoaLumberjack"
github "mxcl/PromiseKit"
github "wikimedia/SWStepSlider"

#Test Libraries
github "facebook/ios-snapshot-test-case"
github "Quick/Nimble"
github "Quick/Quick"

Carthage Output

*** Cloning Quick
*** Cloning Nimble
*** Cloning ios-snapshot-test-case
*** Cloning SWStepSlider
*** Fetching PromiseKit
*** Cloning CocoaLumberjack
*** Fetching OMGHTTPURLRQ
*** Checking out OMGHTTPURLRQ at "3.1.1"
*** Checking out PromiseKit at "3.1.1"
*** Checking out Nimble at "v4.0.1"
*** Checking out SWStepSlider at "1.0.0"
*** Checking out Quick at "v0.9.2"
*** Checking out ios-snapshot-test-case at "2.1.0"
*** Checking out CocoaLumberjack at "2.3.0"
*** xcodebuild output can be found in /var/folders/1y/_dvr5wyd7n7_6z2v_ywv417h0000gp/T/carthage-xcodebuild.sueyJT.log
*** Fetching OMGHTTPURLRQ
*** Building scheme "CocoaLumberjackSwift-tvOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift-watchOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack-tvOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack-watchOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift-iOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack-iOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift-tvOS" in Lumberjack.xcworkspace
*** Building scheme "Nimble-OSX" in Nimble.xcodeproj
*** Building scheme "Nimble-iOS" in Nimble.xcodeproj
*** Building scheme "OMGtvOS" in OMGHTTPURLRQ.xcodeproj
*** Building scheme "OMGiOS" in OMGHTTPURLRQ.xcodeproj
*** Building scheme "OMGwatchOS" in OMGHTTPURLRQ.xcodeproj
*** Building scheme "OMGOSX" in OMGHTTPURLRQ.xcodeproj
*** Building scheme "Quick-OSX" in Quick.xcworkspace
*** Building scheme "Quick-iOS" in Quick.xcworkspace
*** Building scheme "PMKOSX" in PromiseKit.xcodeproj
*** Building scheme "PMKwatchOS" in PromiseKit.xcodeproj
*** Building scheme "PMKiOS" in PromiseKit.xcodeproj
*** Building scheme "SWStepSlider" in SWStepSlider.xcworkspace
*** Building scheme "FBSnapshotTestCase iOS" in FBSnapshotTestCase.xcworkspace
ld: warning: embedded dylibs/frameworks only run on iOS 8 or later
ld: warning: embedded dylibs/frameworks only run on iOS 8 or later
ld: warning: embedded dylibs/frameworks only run on iOS 8 or later
ld: warning: embedded dylibs/frameworks only run on iOS 8 or later
BWARN]Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
[BWARN]Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
[BWARN]Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
[BWARN]Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
warning: All interface orientations must be supported unless the app requires full screen.
warning: A launch storyboard or xib must be provided unless the app requires full screen.
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.

question

Most helpful comment

Or you can try to add Carthage's binary directory directly.
For example, this is my current configuration.

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(SRCROOT)/../../Carthage/Build/Mac

You need to change $(SRCROOT)/../../Carthage/Build/Mac part to fit to your environment.
This is an hack, but unit-tests are usually done in same build machine, so if you just need hot-fix this would be enough.

All 6 comments

You need to add @loader_path/Frameworks to your unit test target's @rpath.

Also, you should consider upgrading your Carthage installation. ☺️

@mdiep Thanks that was the issue.

Is adding @loader_path/Frameworks mentioned anywhere in the docs or is that the default for newer Xcode projects?

I'm guessing that's the default for newer projects, but I don't know for sure.

Or you can try to add Carthage's binary directory directly.
For example, this is my current configuration.

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(SRCROOT)/../../Carthage/Build/Mac

You need to change $(SRCROOT)/../../Carthage/Build/Mac part to fit to your environment.
This is an hack, but unit-tests are usually done in same build machine, so if you just need hot-fix this would be enough.

My test target already has @loader_path/Frameworks in the Runpath Search Paths, but it still doesn't find them. Let me clarify. My unit tests are testing my Framework on macOS. The Framework currently embeds & signs its dependencies. A macOS application is able to load the Framework and everything works. The unit test is not, in that it fails to find the dependencies, not my library under test, which it finds just fine.

EDIT: Maybe it's working now? I can't tell what's going on. I also have to figure how to not embed these libraries in my libraries.

@JetForMe I suppose that you don't have to embed the libraries (more likely frameworks) in your framework. I should be enough if you will point in framework's target build settings Framework Search Paths to Carthage build directory like ../Carthage/Build/iOS. It should be enough to build the framework.
For the unit test target you will have make the same configuration as mentioned above + you will have to add Copy Files with destination to Frameworks and add the frameworks that your frameworks depends on.

Was this page helpful?
0 / 5 - 0 ratings