Xcode unittest build failed with error "Undefined symbols for architecture x86_64"
My unittest target build failed with below error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MCStore", referenced from:
objc-class-ref in MCStoreTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Basic information:
- Xcode6.2
- iOS8.2 SDK
What I have checked:
-
Symbols Hidden by Default
is No -
Other Linker Flags
is -framework XCTest -
Framework Search Paths
is $(SDKROOT)/Developer/Library/Frameworks $(inherited)
According to this link, I need to set Bundle Loader
with below content in unittest target Build Settings
$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
At least as of Xcode 7.3 test targets let you select a "Host Application". In the Test target (but not presently the UI Test target) this automatically populates the "Test Host" build setting, but not the "Bundle Loader", which can lead to classes not being found.
Considering this, if you set your test targets' "Bundle Loader" Build Setting to $(TEST_HOST)
, it will always contain the right value even if you change the Host Application.
This is effectively the opposite of the advice given in the link @yuwen-yan posted, and should amount to less work.
This error may be the result of having wrong test target type, namely ui test target.
UI test targets can't use the internals of the main target, not even with @testable
imports. Unit test targets OTOH can use the internals.
See more details in this answer.
(I believe this has changed in some XCode version which causes confusion. Typical way is just to include a huge bunch of files from the original target in the ui test target. A proper way is to design UI tests in such a way that they don't need or use much code from the main target.)
Experienced the same issue.
What fixed it for me was setting enable modules (c and objective-c)
to YES in the Testing target Build Settings
.