# Cross-compiling to armv7 linux from x86\_64 linux

**URL:** <https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841>\
**Category:** Using Swift\
**Tags:** linux\
**Created:** [December 15, 2018, 7:49pm UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841 "2018-12-15T19:49:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcbless](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jcbless/32/5584_2.png) [@jcbless](https://forums.swift.org/u/jcbless)\
**Post date:** [December 15, 2018, 7:49pm UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841/1 "2018-12-15T19:49:15Z")

</div>

I'd like to cross compile a program for armv7 linux.

To be clear I do not want to cross-compile the compiler, I just want to cross compile a piece of code. Is this currently possible? Could someone please point me to directions about how to do it? I've been experimenting with trying to do it from Swift 4.2.1, but I'd be open to trying it with a different version.

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [December 15, 2018, 8:08pm UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841/2 "2018-12-15T20:08:42Z")

</div>

Yeah this is possible as long as you have both the standard library for the target built and installed as well as have a sysroot for the underlying system. Unfortunately, doing this with the current build-script is not particularly easy as it does not allow for you to easily build just the standard library for the target.

I don't know if anyone is currently shipping a Linux hosted toolchain that can target Linux armv7. I have done that in the past for myself though. If you don't mind building up the various pieces, you can probably use some of my existing work to setup such an environment. You will want to take a look at my [build infrastructure](https://github.com/compnerd/toolchain-infrastructure). You should be able to modify the cache file to build the arm variant instead of x86\_64 for Linux (take a look at `cmake/cache/swift-stdlib-linux.cmake`).

I do have an [attempt](https://github.com/apple/swift/pull/19788) to perform multiple simultaneous builds for the standard library that needs a little bit of work still. Feel free to take a look at that if you like; that should allow you to cross-compile the arm standard library with build script as well.

---

<div class="post-metadata">

**Author:** ![jcbless](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jcbless/32/5584_2.png) [@jcbless](https://forums.swift.org/u/jcbless)\
**Post date:** [December 15, 2018, 9:24pm UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841/3 "2018-12-15T21:24:33Z")

</div>

It appears that cmake/cache/swift-stdlib-linux.cmake is currently an empty file. Do you have another variation you haven't committed and pushed yet? Thanks

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [December 17, 2018, 6:47am UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841/4 "2018-12-17T06:47:10Z")

</div>

Oops, I did have a variation of it, but it did depend on my linux distribution. I would suggest taking a look at the windows one as a starting point. You will need to add a couple of other variables, primarily the `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` will need to be adjusted to get the path to the sysroot.

---

<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 11, 2024, 4:58pm UTC](https://forums.swift.org/t/cross-compiling-to-armv7-linux-from-x86-64-linux/18841/5 "2024-12-11T16:58:45Z")

</div>

If you're still interested, I've got some artifacts and cross compilers generated that can build from x86\_64 or aarch64 to armv7 for Debian and Ubuntu distributions here:

> **[Releases · xtremekforever/swift-armv7](https://github.com/xtremekforever/swift-armv7/releases)**
>
> Swift runtime for Linux Armv7. Contribute to xtremekforever/swift-armv7 development by creating an account on GitHub.

If not, that's fine :)
