Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.34k stars 618 forks source link

Build ios-test-application fails with error: Showing All Messages Undefined symbols for architecture x86_64: #201

Closed vicmns closed 6 years ago

vicmns commented 6 years ago

Hey I'm trying to run the demo ios-test-application using xCode 9.4.1 but I'm getting the following error:

Showing All Messages
> Task :compileDebugIos_x64KotlinNative

Undefined symbols for architecture x86_64:
  "_private_classes_<ktor-utils-ios>_io.ktor.util.DelegatingMutableSet_16", referenced from:
      _kfun:jsonContent#internal in combined.o
  "_private_functions_<ktor-utils-ios>_kfun:io.ktor.util.DelegatingMutableSet.iterator()kotlin.collections.MutableIterator<#GENERIC>_52", referenced from:
      _kfun:jsonContent#internal in combined.o

ld: symbol(s) not found for architecture x86_64

Looking at the sh script I found that the target for iPhone Simulator is named ios_x64, with task compileDebugIos_x64KotlinNative. Are both the same architecture and this is only a issue with naming?

vicmns commented 6 years ago

It is also failing when trying to run it on a physical device"

Showing All Messages
> Task :compileDebugIos_arm64KotlinNative

Undefined symbols for architecture arm64:
  "_private_classes_<ktor-utils-ios>_io.ktor.util.DelegatingMutableSet_16", referenced from:
      _kfun:jsonContent#internal in combined.o
  "_private_functions_<ktor-utils-ios>_kfun:io.ktor.util.DelegatingMutableSet.iterator()kotlin.collections.MutableIterator<#GENERIC>_52", referenced from:
      _kfun:jsonContent#internal in combined.o

ld: symbol(s) not found for architecture arm64
sandwwraith commented 6 years ago

Looks like an issue with ktor-http-client. @e5l could you please take a look?

e5l commented 6 years ago

Hi, @vicmns. It looks like you try to use x64 framework on the real device.

There are two frameworks in your build directory: arm64, x64. For the simulator consider using the x64 framework, and arm64 for the real device.

vicmns commented 6 years ago

Hey @e5l oh my you were right... I don't remember when I changed the gradle file outPutKind to Framework...

Thanks for the note.

A quick question... in the case that a framework it's built. How can I managed the created frameworks so I can use them without worrying about the device architecture?

I have a project where I create the framework for both platforms. But even when I import them to the xCode project, the compiler is still showing linking errors...

Undefined symbols for architecture x86_64:
Showing All Messages
  "_OBJC_CLASS_$_KCDPTestJSONParsing", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
e5l commented 6 years ago

As I know there is no out of the box solution. But you could try to merge frameworks into universal framework. Maybe something like that could help: https://medium.com/swiftindia/build-a-custom-universal-framework-on-ios-swift-549c084de7c8

e5l commented 6 years ago

Consider avoid including both frameworks into the single target. I'd prefer to create 2 run configurations: for simulator and for a device.

vicmns commented 6 years ago

Ok so for the sake of simplicity, I just imported the x64 framework to the project. Xcode can find the code reference so auto complete it's working.

But again when I try to compile the app on the simulator I'm getting the same error...

Showing All Messages
Ld /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Products/Debug-iphonesimulator/crossparser.app/crossparser normal x86_64
    cd /Users/vicmns/Documents/git/project-awesome-o/ios
    export IPHONEOS_DEPLOYMENT_TARGET=11.4
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -L/Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Products/Debug-iphonesimulator -F/Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Products/Debug-iphonesimulator -F/Users/vicmns/Documents/git/project-awesome-o/ios/build/lib/main/debug/ios_x64 -F/Users/vicmns/Documents/git/project-awesome-o/ios/crossparser -filelist /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Intermediates.noindex/crossparser.build/Debug-iphonesimulator/crossparser.build/Objects-normal/x86_64/crossparser.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=11.4 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Intermediates.noindex/crossparser.build/Debug-iphonesimulator/crossparser.build/Objects-normal/x86_64/crossparser_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Intermediates.noindex/crossparser.build/Debug-iphonesimulator/crossparser.build/Objects-normal/x86_64/crossparser.swiftmodule -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Intermediates.noindex/crossparser.build/Debug-iphonesimulator/crossparser.build/crossparser.app-Simulated.xcent -framework KotlinChartDataParser -Xlinker -dependency_info -Xlinker /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Intermediates.noindex/crossparser.build/Debug-iphonesimulator/crossparser.build/Objects-normal/x86_64/crossparser_dependency_info.dat -o /Users/vicmns/Library/Developer/Xcode/DerivedData/crossparser-chtnyvwqbhztzebfotbubkgdknfh/Build/Products/Debug-iphonesimulator/crossparser.app/crossparser

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_KCDPTestJSONParsing", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is how it looks in my project: screen shot 2018-08-27 at 12 23 35 pm

Just as note: this doesn't happen with the arm64 framework if I run it on a real device. The only thing that I had to do it was to disable Bitcode to the app config...

e5l commented 6 years ago

Could you show your build.gradle dependencies sections?

vicmns commented 6 years ago

Ok, I'm finally able to build the project on iOS. In the end I created a new iOS project and copy correctly the framework. I made a lot of changes so maybe I broke something in the way...

Thanks for the help!