XCTest build errors for test target Xcode 5:

夙愿已清 提交于 2019-11-28 07:14:19

Check your Framework Search Paths in your test target settings. These can be corrupted when adding the XCTest Framework.

Adding XCTest to one of my projects prepended a "/" to the paths causing them to not find the correct version.

None of the above answers worked for me. I did find an answer here in a comment left by Tim Macfarlane.

For linker errors looking for a class in your app... set the “Symbols Hidden by Default” build setting to “NO” in your app target. This makes all your app classes available to your test target automatically...

So, that means:

  • Project Navigator > Select your project
  • Targets > Select your App (not Tests)
  • Build Settings > Search for "Symbols Hidden By Default"
  • "Symbols Hidden By Default" > Change it from "YES" to "NO"

I had the same issue; the problem (for me, at least) was that the FRAMEWORKS_SEARCH_PATHS build setting listed the SDK frameworks folder after the main developer frameworks folder.

The frameworks included with Xcode have three separate builds: one for OS X, one for iOS (device), and a third for the iOS Simulator. The OS X build is in the main developer folder, with the other two being under their respective platform folders. The rub here is that if you don't specify to search the SDK folders first (which are within the platform folders), Xcode (or more correctly, the linker) will find the OS X build first and produce the error you see.

The solution is simple, put:

FRAMEWORK_SEARCH_PATHS = $(SDKROOT)/Developer/Library/Frameworks $(inherited)

in your build settings. If you're putting build settings in the project file (I don't recommend it, but that's another question for another day), it's just named "Framework search paths."

NOTE: Sometimes Xcode's a little slow to catch on; you'll probably need to delete your build folder (better than just a clean) for this to take effect.

Aist Marabu

Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:

"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)

So, for me, what I was missing after trying everything else in this post, was:

Other Linker Flags:

-framework XCTest

I'm currently using Xcode 6.0 (with the iOS 8 SDK) so I'm surprised that the "Edit > Refactor > Convert to XCTest..." option doesn't add this automatically.

I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.

I had this problem upon adding another file for tests. If you do this with (CMD + N) be sure to only target the Test Bundle (ie. 'AppNameTests').

I guess only these .xctest bundles have access to the XCTest Framework.

I had the same issue after renaming my Target name and moving things around. It turned out that my tests were part of my Main Target. Make sure that you all your test files belong only to your test target.

Just select a .m file, make sure you have the right pane open.

I had the same problem when tried to build XCTTest-based unit tests with pre-7.0 SDK. When I chose 7.0 as my Base SDK then that kind of link error disappeared.

Had a the same issue but ended up with a slightly different solution.

select XCTest.framework and make sure that only your test folder is checked under Target Membership.

Marius

Make sure that the Search Framework Path (FRAMEWORK_SEARCH_PATHS) for the YourProjectTests target includes the path $(SDKROOT)/Developer/Library/Frameworks, and that this one is listed before $(inherited).

In my case, both paths were present, but $(inherited) was the first one.

Credit goes to https://stackoverflow.com/users/181947/brian-clear on Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!