Swift test give error Undefined symbols for architecture x86_64
I managed to successfully build and test your package by doing the following modifications:
- renamed the package name to
VnkSwift
, for some reasons the build tool doesn't like dashes in package name, nor it works when you have underscores in the generated package name (so renaming the package tovnk_swift
to make sure the import statement and the package name match didn't work) - renamed the test folder to
VnkSwiftTests
in order for the linker to know what to link against; seems this is a precondition for the linker to know to link against the package - finally, renamed
main.swift
to something else (I usedutils.swift
). The thing is that the presence ofmain.swift
instructs the build tool to generate an executable, and linking against an executable doesn't work very well. After the rename, had to comment theif
code, as global running code can only belong tomain.swift
.
To conclude:
- Avoid non-alphanumeric package names
- Package name and test directory name must be in sync
- Make sure you don't have a
main.swift
file to make sure the package can be linked against
Why can't a unit test target link against executables?
It's because both the test bundle and the executable bundle have global executing code (aka the main function), so the linker doesn't know which one of them to pick. When testing from Xcode, the test bundle runs into the context of the application - it doesn't link against it, like in the situation right here.
Xcode also has this problem when creating a command line tool - you can't unit test that target, if you want to unit test the code then you have to create a library that will be linked by both the tool and the unit test target (or include the files in both targets)
Xcode unittest build failed with error Undefined symbols for architecture x86_64
According to this link, I need to set Bundle Loader
with below content in unittest target Build Settings
$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
Xcode build failure Undefined symbols for architecture x86_64
It looks like you are missing including the IOBluetooth.framework in your project. You can add it by:
Clicking on your project in the upper left of the left pane (the blue icon).
In the middle pane, click on the Build Phases tab.
Under "Link Binary With Libraries", click on the plus button.
Find the IOBluetooth.framework from the list and hit Add.
This will make sure that the IOBluetooth.framework definitions are found by the linker. You can see that the framework is a member of your target by clicking on the framework in the left pane and seeing the framework's target membership in the right pane (note I've moved the framework under the Frameworks group for organization purposes):
RxTest: Undefined symbols for architecture x86_64 and arm64
After a lot of searches, As somebody suggests here for another similar issue I found that this error will be solved by importing RxCocoa
.
Related Topics
How to Embed Third Party Framework on Ionic Capacitor Custom Plugin
How to Speed Up Updating Relationship Among Tables, After One or Both Tables Are Already Saved
How to Demonstrate a Zombie Object in Swift
How to Read a Property List from Data in Swift 3
Compare Three Values for Equality
Why Is Swift's Ternary Operator So Picky About Whitespace
Swift [1,2] Conforms to Anyobject But [Enum.A, Enum.B] Does Not
Swiftui Label Text and Image Vertically Misaligned
Swift: Programmatically Enumerate Outgoing Segues from a Uiviewcontroller
Preventing a Coredata Crash for Upgrading Users
Realitykit - Adding Modelentity to an Argeoanchor
Uialertview Is Crashing App on iOS 7
Core Data Predicate Not Working
How to Encode an Unmanaged<Seckey> to Base64 to Send to Another Server