Hello!
Need your help in order to understand the reason of missed swift_addNewDSOImage symbol error when using Swift compiler built on macOS cross-compile host. Swift compiler build with same sources on Ubuntu 18.04.1 (via Vagrant) works without such error. Seems pure CMake configuration issue.
Here is an error I am getting:
swiftrt.o:SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
From what I understand by exploring CMake files that symbol swift_addNewDSOImage
should be inside libswiftCore.so
shared object. And it seems inside:
$ nm /.../android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android/libswiftCore.so | grep swift_addNewDSOImage
003c01a4 T swift_addNewDSOImage
Undefined reference also present in swiftrt.o
file.
$ nm /.../android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android/armv7/swiftrt.o | grep swift_addNewDSOImage
U swift_addNewDSOImage
I am trying to understand purpose of swiftrt.o
file and a reason of dedicated configuration for ImageInspectionELF.cpp
file in swift/stdlib/public/runtime/CMakeLists.txt
CMake file.
Thank you!
Here is a detail log.
mkdir -p "/Users/vova/Repositories/GitHub/Projects/android-on-swift/Build/armv7a/Hello"
cd /Users/vova/Repositories/GitHub/Projects/android-on-swift/Build/armv7a/Hello
PATH=/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/bin:$PATH \
swiftc \
-v -tools-directory /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin \
-target armv7-none-linux-androideabi \
-Xcc -I/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/sysroot/usr/include \
-Xcc -DDEPLOYMENT_TARGET_ANDROID \
-Xcc -DDEPLOYMENT_RUNTIME_SWIFT \
-Xlinker -v /Users/vova/Repositories/GitHub/Projects/android-on-swift/Projects/Hello/hello.swift
Swift version 5.0-dev (LLVM f63b283c71, Clang 41ac4c4262, Swift 8e38b67d66)
Target: armv7-none-linux-android
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/bin/swift
-frontend -c
-primary-file /Users/vova/Repositories/GitHub/Projects/android-on-swift/Projects/Hello/hello.swift
-target armv7-none-linux-android -disable-objc-interop
-Xcc -I/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/sysroot/usr/include
-Xcc -DDEPLOYMENT_TARGET_ANDROID
-Xcc -DDEPLOYMENT_RUNTIME_SWIFT -color-diagnostics
-module-name hello
-o /var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-16dd94.o
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/bin/swift-autolink-extract /var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-16dd94.o
-o /var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-d5644e.autolink
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/clang++
-fuse-ld=gold -B /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin
-pie -target armv7-none-linux-androideabi /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android/armv7/swiftrt.o /var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-16dd94.o
@/var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-d5644e.autolink
-L /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android
-lswiftCore --target=armv7-none-linux-android -v -Xlinker -v -o hello
Android (4751641 based on r328903) clang version 7.0.2 (https://android.googlesource.com/toolchain/clang 003100370607242ddd5815e4a043907ea9004281) (https://android.googlesource.com/toolchain/llvm 1d739ffb0366421d383e04ff80ec2ee591315116) (based on LLVM 7.0.2svn)
Target: armv7-none-linux-android
Thread model: posix
InstalledDir: /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin
Found candidate GCC installation: /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Selected GCC installation: /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Candidate multilib: thumb;@mthumb
Candidate multilib: armv7-a;@march=armv7-a
Candidate multilib: armv7-a/thumb;@march=armv7-a@mthumb
Candidate multilib: .;
Selected multilib: armv7-a;@march=armv7-a
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.gold
--sysroot=/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../sysroot
-pie -X --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker
-o hello /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../sysroot/usr/lib/../lib/crtbegin_dynamic.o
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/lib64/clang/7.0.2/lib/linux/arm
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../sysroot/usr/lib/../lib
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a
-L/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../sysroot/usr/lib
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android/armv7/swiftrt.o
/var/folders/7l/skdbvw8s5jx0g9vs5_qrkync0000gt/T/hello-16dd94.o -lswiftSwiftOnoneSupport -lswiftCore -lswiftCore
-v -lstdc++ -lm -lgcc -lgcc -ldl -lc -lgcc -lgcc -ldl /Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/ndk/bin/../sysroot/usr/lib/../lib/crtend_android.o
/Users/vova/Repositories/GitHub/Projects/android-on-swift/Install/armv7a-macos/swift/usr/lib/swift/android/armv7/swiftrt.o:SwiftRT-ELF.cpp:function swift_image_constructor(): error: undefined reference to 'swift_addNewDSOImage'
GNU gold (GNU Binutils 2.27.0.20170315) 1.12
clang70++: error: linker command failed with exit code 1 (use -v to see invocation)
btw: Not sure if Swift officially support Android compilation on macOS Cross-Compile host. I am using this Automated workflow to build Swift for Android on macOS: GitHub - vgorloff/swift-everywhere-toolchain: Automated workflow to compile Swift Toolchain, for making Android apps with Swift.