Description
On x86-64 Linux, I tried to compile aarch64 linux binary.
I have created an aarch64 sdk that I have build on a Mac, and copy on x86-64 linux build system.
Then, I completely:
$>swift build -Xswiftc '-disable-round-trip-debug-types' --swift-sdk 6.0.3-bookworm-arm64
And I have link error :
error: link command failed with exit code 1 (use -v to see invocation)
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/aarch64-linux-gnu/Scrt1.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/aarch64-linux-gnu/crti.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/gcc/aarch64-linux-gnu/12/crtbeginS.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/usr/lib/swift/linux/aarch64/swiftrt.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/AdjacentPairs.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Algorithms.swiftmodule.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Chain.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Chunked.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Combinations.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Compacted.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Cycle.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/EitherSequence.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/FirstNonNil.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/FlattenCollection.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Grouped.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Indexed.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Intersperse.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Joined.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Keyed.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/MinMax.swift.o is incompatible with elf64-x86-64
Activity
xtremekforever commentedon Mar 2, 2025
What did you invoke to generate the aarch64 SDK? It almost looks like you created an SDK for x86_64 but with an arm64 image.
dscreve commentedon Mar 2, 2025
swiftTarget="aarch64-unknown-linux-gnu"
swift run swift-sdk-generator make-linux-sdk --with-docker --from-container-image dlta-swift-docker-arm64 --target ${swiftTarget} --sdk-name 6.0.3-bookworm-arm64
DockerFile:
FROM swift:6.0.3-bookworm
RUN apt update && apt -y install openssl libssl-dev pkg-config && apt -y clean
$>docker build --platform linux/arm64 -t dlta-swift-docker-arm64 -f dockerFile .
Note : SDK has been created on a Mac with M1 processor, and compilation is performed on linux x86-64 system targeting linux aarch64.
xtremekforever commentedon Mar 2, 2025
This looks like it is caused by your other ticket #192 . I saw these exact errors on my system when I tried to link openssl using a
.systemLibrary
with thepkgConfig
directive. It's like swiftpm is trying to link x86_64 and aarch64 together, which is incompatible. Try my suggest on #192 and see if it also fixes this ticket.@MaxDesiatov @euanh do you guys have any idea why using
pkgConfig
on a.systemLibrary
would cause Swift PM to look for libraries on the host instead of the target? Maybe a use case that hasn't been covered/handled, or a bug?dscreve commentedon Mar 2, 2025
This works fine.
euanh commentedon Mar 6, 2025
This is swiftlang/swift-package-manager#7409. It's currently necessary to set
PKG_CONFIG_SYSROOT_DIR
andPKG_CONFIG_PATH
to point to the SDK root directory.