Rugen Heidbuchel Rugen Heidbuchel - 2 months ago 19
Swift Question

Xcode 6.3 swift framework: Undefined symbols for architecture x86_64

I updated to Xcode 6.3, but now my project (framework) won't build anymore. It's a pure swift project. All my files compile correctly (The part "Compile swift source files" is checked), but I get a linking error for my tests (myProjectTests.xctest):

Undefined symbols for architecture x86_64:
"__TWPSiSs10Comparable14MathEagleTests", referenced from:
__TFC14MathEagleTests11MatrixTests45testRandowWithDimensionsIntervalGeneratorInitfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests21testSubscriptRangeSetfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests35testSubscriptRowRangeColumnRangeSetfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests30testSubscriptRowRangeColumnSetfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests30testSubscriptRowColumnRangeSetfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests13testMatrixMapfS0_FT_T_ in MatrixTests.o
__TFC14MathEagleTests11MatrixTests24testMatrixMapPerformancefS0_FT_T_ in MatrixTests.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


The strange thing is that Comparable is a swift built-in protocol, so I don't think it has anything to do with my code?
All references are from my test files as well, so it's not my main project...

Answer

I finally found how to fix it. I used several protocols like this:

extension Int: Addable, Negatable, Substractable, Multiplicable, Dividable, Modulable, Powerable, SetCompliant, BasicMathValue, FullMathValue, MatrixCompatible {}

I think the bug was caused by the fact that some of these protocols use the Comparable protocol, as an example:

protocol FullMathValue: Equatable, Comparable, Addable, Negatable, Substractable, Multiplicable, Dividable, Powerable, SetCompliant, IntegerLiteralConvertible {}

When I added the Comparable protocol to the extensions explicitly everything worked:

extension Int: Comparable, Addable, Negatable, Substractable, Multiplicable, Dividable, Modulable, Powerable, SetCompliant, BasicMathValue, FullMathValue, MatrixCompatible {}

The strange this is that the errors only get caused by the Int and UInt types, so all Int8, ... and UInt8, ... as well. Float and Double didn't cause any trouble.

Is this a bug I need to report, or is there an explanation for this behaviour?

Comments