# Linux cross-compile x64 to aarch64

**URL:** https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752
**Category:** Usage
**Created:** [August 26, 2020, 11:32pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752 "2020-08-26T23:32:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Frederick\_Gotham](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@Frederick\_Gotham](https://discourse.cmake.org/u/Frederick_Gotham)
#### Post date: [August 26, 2020, 11:32pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/1 "2020-08-26T23:32:14Z")

</div>

Unless anyone can convince me of otherwise, I’ve given up on _cmake_ being able to cross-compile on Linux from x64 to aarch64.

I started this topic about it earlier on a C group:

[https://groups.google.com/forum/#!topic/comp.lang.c/B9msZxHI-as](https://groups.google.com/forum/#!topic/comp.lang.c/B9msZxHI-as)

I think tomorrow I will take the CMakeLists.txt files, generate GNU Makefiles from them, and then dismantle the GNU Makefiles so that I have simple one-liner commands like:

```
aarch64-linux-gnu-gcc -o interface.o -c interface.c
aarch64-linux-gnu-gcc -o computation.o -c computation.c
aarch64-linux-gnu-gcc -o calculator interface.o computation.o

```

Then I’ll just collect all these one-liner commands together and put them in a script, “make.sh”.

I even tried editing the cmake source code for “try\_compile” in order to try get rid of the error about not being able to find an intermediary executable file, but I didn’t get anywhere.

I haven’t heard of anyone successfully cross-compiling with cmake on Linux from x64 to aarch64.

---

<div class="post-metadata">

### Author: ![Dakon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dakon/32/854_2.png) [@Dakon](https://discourse.cmake.org/u/Dakon)
#### Post date: [August 27, 2020, 11:55am UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/2 "2020-08-27T11:55:13Z")

</div>

> Unless anyone can convince me of otherwise, I’ve given up on _cmake_  
> being able to cross-compile on Linux from x64 to aarch64.

I’m doing this every day and it works fine. Documentation is here:

[https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html)

---

<div class="post-metadata">

### Author: ![Frederick\_Gotham](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@Frederick\_Gotham](https://discourse.cmake.org/u/Frederick_Gotham)
#### Post date: [August 27, 2020, 1:57pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/3 "2020-08-27T13:57:48Z")

</div>

I’ve read the manual and tried a few different “toolchain” files. Still can’t make an aarch64 build on a x64 host (both Linux).

---

<div class="post-metadata">

### Author: ![Dakon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dakon/32/854_2.png) [@Dakon](https://discourse.cmake.org/u/Dakon)
#### Post date: [September 27, 2020, 7:54pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/4 "2020-09-27T19:54:02Z")

</div>

Mine looks like this:

```cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# specify the cross compiler
set(CMAKE_C_COMPILER /somewhere/bin/aarch64-unknown-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /somewhere/bin/aarch64-unknown-linux-gnueabi-g++)

# where is the target environment
set(CMAKE_FIND_ROOT_PATH /somewhere/sysroot)
set(CMAKE_SYSROOT /somewhere/sysroot)

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# automatically use the cross-wrapper for pkg-config
set(PKG_CONFIG_EXECUTABLE "/somewhere/bin/aarch64-unknown-linux-gnueabi-pkg-config" CACHE FILEPATH "pkg-config executable")

```

---

<div class="post-metadata">

### Author: ![godfool](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@godfool](https://discourse.cmake.org/u/godfool)
#### Post date: [November 16, 2020, 6:53pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/5 "2020-11-16T18:53:23Z")

</div>

This doesn’t work for me either. It just won’t find any libraries. Is this on Ubuntu or Debian? What’s your actual sysroot?

For reference, here’s the thread with my problem: [Cross compile for aarch64 on Ubuntu](https://discourse.cmake.org/t/cross-compile-for-aarch64-on-ubuntu/2161/7)

---

<div class="post-metadata">

### Author: ![Dakon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dakon/32/854_2.png) [@Dakon](https://discourse.cmake.org/u/Dakon)
#### Post date: [November 17, 2020, 1:18pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/6 "2020-11-17T13:18:44Z")

</div>

The point is that I have an actual sysroot, i.e. everything that belongs to the aarch64 platform is in that folder. This is different from your mixed setup.

---

<div class="post-metadata">

### Author: ![godfool](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@godfool](https://discourse.cmake.org/u/godfool)
#### Post date: [November 17, 2020, 3:22pm UTC](https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/7 "2020-11-17T15:22:08Z")

</div>

I gathered. My workaround is to copy all aarch64 libs into my “sysroot”, together with the headers. It builds, but there’s got to be a cleaner way in CMake for Ubuntu multi arch. Thanks for replying!
