# Aarch64 cross compilation not working with \`--static-swift-stdlib\`

**URL:** <https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439>\
**Category:** Server\
**Tags:** cross-compilation, server\
**Created:** [December 6, 2024, 9:16pm UTC](https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439 "2024-12-06T21:16:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [December 6, 2024, 9:16pm UTC](https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439/1 "2024-12-06T21:16:13Z")

</div>

i am trying to cross-compile a Swift application on Linux from an x86\_64 host to an AArch64 target, using the Swift 6.0.2 toolchain.

the build works when using the default dynamically linked standard library, but it fails due to missing `static-stdlib-args.lnk` when i use the `--static-swift-stdlib` option.

```plaintext
SwiftDriver/GenericUnixToolchain+LinkerSupport.swift:266: 
Fatal error: /home/ubuntu/aarch64/swift/usr/lib/swift/linux/static-stdlib-args.lnk not found

```

i am interested in statically linking the Swift runtime because it is very logistically challenging when using Swift on the server to keep the runtime in sync with the application.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [December 7, 2024, 12:46am UTC](https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439/2 "2024-12-07T00:46:06Z")

</div>

We'd need more info on the config you're using, but there's an obvious reason this is failing: you're not using the static resource directory. Cross-compilation depends on three core compiler flags: `-target` to choose the triple, `-sdk` to choose the sysroot for the platform's C/C++ headers and libraries, and `-resource-dir` to choose the Swift runtime libraries for your platform.

Swift toolchains and SDKs come with two separate resource directories for static versus dynamic linking: `usr/lib/swift/linux/` in the linux toolchain contains the runtime and corelibs as shared libraries, whereas `usr/lib/swift_static/linux/` contains them as static archives.

The compiler driver will choose the latter for static linking if you allow it, but the error you're seeing usually happens if you choose static linking but forcibly pass in the incorrect shared resource directory with `-resource-dir usr/lib/swift`.

That's my best guess without ever having seen your config.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [December 7, 2024, 10:55pm UTC](https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439/3 "2024-12-07T22:55:31Z")

</div>

you’re a lifesaver, thanks!

if anyone’s interested, i set up a GitHub Actions task in this repo that builds a cross-compilation environment as a Docker image and pushes it to DockerHub:

> **[GitHub - tayloraswift/swift-cross-aarch64: Docker image for Swift AArch64 cross-compilation](https://github.com/tayloraswift/swift-cross-aarch64)**
>
> Docker image for Swift AArch64 cross-compilation

[https://hub.docker.com/r/tayloraswift/swift-cross-aarch64](https://hub.docker.com/r/tayloraswift/swift-cross-aarch64)

---

<div class="post-metadata">

**Author:** ![xtremekforever](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/xtremekforever/32/43018_2.png) [@xtremekforever](https://forums.swift.org/u/xtremekforever)\
**Post date:** [December 8, 2024, 1:14pm UTC](https://forums.swift.org/t/aarch64-cross-compilation-not-working-with-static-swift-stdlib/76439/4 "2024-12-08T13:14:31Z")

</div>

Cool deal! I can see this as being useful. I'm working on my side to create some cross compilation SDKs for aarch64 and armv7 that can be installed using `swift sdk install` (or `swift experiemental-sdk install` for 5.10). The idea is so that you don't have to use the generator for the SDK, you can just download it from the GitHub page and run with it.

But awesome stuff, I see that this cross compilation Docker would be great for cross compiling from GitHub actions or from a CI!
