Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode unittest build failed with error "Undefined symbols for architecture x86_64"

Tags:

xcode

ios

People also ask

How do I fix undefined symbol in XCode?

The error Undefined symbols for architecture arm64: "_OBJC_CLASS_$_SKAdImpression" during the iOS build usually happens if XCode or CocoaPods version is lower than required. To fix it update XCode to 12.5 or higher and CocoaPods to 1.10. 0 or higher.

What is undefined symbols for architecture x86_64?

Why Is the Undefined Symbols for Architecture x86_64: Error Happening? This error is happening due to the lack of included values inside the declared statements in your code. The browser is going to render the information incorrectly and show this error, especially if you are working with Main and Similarity tools.


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.


In my particular case I was trying to test release configuration and was getting this particular error. After experimenting with different compilation flags I found out that setting Enable Testability for release configuration on my projects (not particular targets but might work too) did the trick.

enter image description here