34

I have problems running a project in Xcode 5.0.2

I get the following error:

dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest
  Referenced from: /Users/chris/Library/Developer/Xcode/DerivedData/relatio-cwlmozvklaldmictbbjthzuoxnxz/Build/Products/Debug/relatio.app/Contents/MacOS/relatio

Reason: image not found (lldb)

How do I solve this issue?

Chris Hanson
  • 52,684
  • 8
  • 70
  • 102
user637338
  • 2,080
  • 1
  • 19
  • 22
  • 4
    This is how I solved the problem: 1. Navigate to the project's "Build Settings" 2. Search for "Runpath Search Paths" 3. Enter the following path in the column below the product name: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/ – user637338 Dec 01 '13 at 23:09
  • 2
    You can answer your own question by writing an answer instead of a comment. – Saaru Lindestøkke Dec 01 '13 at 23:37

15 Answers15

28

It looks like your main target is linking to XCTest.framework as well as your test target. It should only be linked to the main target.

1) Go to Project settings

2) Go to your apps main target -> other linker flags

3) remove '-framework XCTest'

4) make sure the 'other linker flags' field for your test target still contains '-framework XCTest'

Akram
  • 7,460
  • 8
  • 43
  • 71
Robert Wagstaff
  • 2,594
  • 1
  • 24
  • 40
18

I ran into this error by renaming my targets one of which was a testing target. After reading the other answers I realized that my Build Phases > Compile Sources was including test classes as compile sources for non-test targets which then tried to import the XCTest framework.

Removing the test classes from my regular target’s Compile Sources solved this for my case.

JoePasq
  • 5,236
  • 2
  • 30
  • 45
7

The problem here is that, according to the dyld error message you posted, your application is linking against XCTest.framework. That's incorrect; only your test bundle needs to link against XCTest.framework since only your test bundle contains tests.

Chris Hanson
  • 52,684
  • 8
  • 70
  • 102
7

I solved this problem this way. I have edited scheme, at "Build" tab ticked "Run".

enter image description here

Hot'n'Young
  • 401
  • 4
  • 11
6

I had similar problem with OCMock library and solution is:

target :"Application Tests", :exclusive => true do
    pod 'OCMock'
end
Leszek Zarna
  • 2,973
  • 24
  • 25
  • For those dummies like me, if your application is named MyApp, the target here is MyAppTests ... – Kheldar Oct 14 '14 at 13:58
  • Careful, if you do 'exclusive => true' you are NOT including any more pods from other targets. – RGML Apr 02 '15 at 09:36
  • Note that :exclusive has since been replaced with `inherit! :search_paths`. See http://blog.cocoapods.org/CocoaPods-1.0-Migration-Guide/ – Jalakoo Oct 18 '18 at 21:21
  • @LeszekZarna Sure, I added the post 1.0 syntax to your existing example. – Jalakoo Nov 16 '18 at 03:44
5

In my case It was RxTests added by Swift Package Manager to main application target. In pods you decide which Rx components add to which target, but SPM adds it all to main target as default.

milczi
  • 4,630
  • 1
  • 22
  • 19
4

This is how I solved the problem:

  1. Navigate to the project's "Build Settings"
  2. Search for "Runpath Search Paths"
  3. Enter the following path in the column below the product name: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/
user637338
  • 2,080
  • 1
  • 19
  • 22
  • 1
    This is incorrect in a couple of ways. First, it will lead to a dependency of your application on XCTedt.framework, which is only available within Xcode. Second, you're using an absolute path, which isn't guaranteed to be the same from Mac to Mac (for example if you have multiple versions of Xcode installed). – Chris Hanson Jan 01 '14 at 19:09
  • @ChrisHanson: This is really working with Xcode 5.1.1. But note that you don't need to provide Absolute Path, relative path should be provided. My scenario was, I have build Dynamic Frameworks with Xcode 6, then i tried to used it in Xcode 5.1.1 in my application, I received same issue describe here... I tried giving path of my Dynamic framework in "Runpath Search paths" and it worked.. – DShah Jul 07 '14 at 05:52
2

In my main Target's "Link Binary With Libraries" (under Build Phases), it was the testing framework I was using (Nimble.framework) that was causing the problem. Removed it, and everything's fine!

Rogare
  • 3,104
  • 3
  • 24
  • 43
1

enter the reference of your framework on framework search path AND Run path search path under "Build Settings"---...Now all set to invoke your projects by using import

1

I have same issue is because i add a new file into the framework. So just run "pod install" solved my issue. But make sure your pod under Tests target too.

William Hu
  • 12,918
  • 8
  • 85
  • 98
0

Just for the ones that came up with the same issue:

Check on the lateral right menu which has to look like that:

Should be

And has not have to look like that:

Shouldn't be

Eironeia
  • 683
  • 7
  • 19
0

For our case, we want to use Mockingjay for both app target and test target

target 'MyProject' do
  pod 'Mockingjay/Core'
  # all pods that are not test go here

  target 'MyProjectTest' do
      inherit! :search_paths
      pod 'Mockingjay/XCTest'
      pod 'Quick', ' ~> 0.9.2'
      # .. all test pods go here
  end
end
Ted
  • 19,425
  • 10
  • 78
  • 99
0

A solution that worked for me was changing your test target's inherit attribute in your Podfile from :search_paths to :complete. Although this answer suggests that :search_paths is designed for test environments.

target 'myapp' do    
  use_frameworks!

  target 'myappTests' do
    #inherit! :search_paths
    inherit! :complete
  end

end
Rem-D
  • 513
  • 5
  • 8
0

I had this error using ios-snapshot-test-case v5.0.2 via Carthage. The problem is related to XCode 11. Apple renamed libswiftXCTest.dylib to libXCTestSwiftSupport.dylib and added XCTest.swiftmodule which has the same symbols in it and can work in place of the old one. But Apple forgot to tell iOS 11.x simulators about this change.

So you need to fix the older iOS version simulators. Here is the terminal command that fixed it for me:

sudo zsh -c ' sourcedir="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib"; 
targetdir="/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 11.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib"; 
ln -s $sourcedir/libXCTestSwiftSupport.dylib $targetdir/libswiftXCTest.dylib;
ln -s $sourcedir/XCTest.swiftmodule $targetdir/XCTest.swiftmodule'

See my comment here: https://github.com/CocoaPods/CocoaPods/issues/9165#issuecomment-573523322

CommaToast
  • 9,468
  • 7
  • 46
  • 65
0

Go to General > Targets (Left side).

You might have 2nd item containing the word test/s. Click it.

In this general settings > Testing > Host application > Select from options (your app name). That's it!

Calculuswhiz
  • 3,244
  • 9
  • 21
  • 35