# Cross compiling to ARM, CMAKE can't find libraries

**URL:** https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080
**Category:** Usage
**Created:** [February 21, 2022, 8:37pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080 "2022-02-21T20:37:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nwetter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/c57346/32.png) [@nwetter](https://discourse.cmake.org/u/nwetter)
#### Post date: [February 21, 2022, 8:37pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/1 "2022-02-21T20:37:32Z")

</div>

I’m trying to get our existing project to cross compile because it takes so long to compile on the target. I’ve looked through many articles and tutorials and it looks simple, but it just won’t work. I know the libraries are all correct because I copied them straight from the target.

The target is an IMX6 (armv7) board running Debian. We’re using CLANG 6.0 for the project, but at some point in troubleshooting I changed to GCC to see if I’d have an easier time.

Any help would be much appreciated. I’ve spent a lot of time on this so far and don’t feel I’ve really gotten anywhere and I’m pretty frustrated.

My toolchain file:

```auto
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER /bin/arm-linux-gnueabihf-gcc-9)
set(CMAKE_CXX_COMPILER /bin/arm-linux-gnueabihf-g++-9)

set(CMAKE_FIND_ROOT_PATH /lib/arm-clearview/arm-linux-gnueabihf)

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY_CMAKE_FIND_ROOT_PATH)
set(CMAKE_PREFIX_PATH /lib/arm-clearview/arm-linux-gnueabihf)
set(CMAKE_SYSROOT /lib/arm-clearview/arm-linux-gnueabihf)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

```

[Full output from CMAKE can be seen here](https://pastebin.com/vnTeYnHb).

Here’s proof that the libraries are really there. This is one of the libraries linked on the target that I copied to the host:

```auto
nate@nate-ubuntuvm:~/hosthome/Documents/GitHub/clearview/cmake-cross$ ls -l /lib/arm-clearview/arm-linux-gnueabihf/libarchive.so
lrwxrwxrwx 1 root root 20 Feb 8 17:30 /lib/arm-clearview/arm-linux-gnueabihf/libarchive.so -> libarchive.so.13.2.2
nate@nate-ubuntuvm:~/hosthome/Documents/GitHub/clearview/cmake-cross$ ls -l /lib/arm-clearview/arm-linux-gnueabihf/libarchive.so.13.2.2
-rw-r--r-- 1 root root 473248 Feb 8 17:30 /lib/arm-clearview/arm-linux-gnueabihf/libarchive.so.13.2.2

```

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [February 21, 2022, 10:01pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/2 "2022-02-21T22:01:03Z")

</div>

The sysroot should be setup like a normal Linux root filesystem **when you remove the sysroot prefix**. Your library was probably in /usr/lib on the target, but here it is in /.

---

<div class="post-metadata">

### Author: ![nwetter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/c57346/32.png) [@nwetter](https://discourse.cmake.org/u/nwetter)
#### Post date: [February 21, 2022, 10:29pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/3 "2022-02-21T22:29:45Z")

</div>

Thank you for the response. I don’t 100% follow–could you please elaborate? Are there specific changes you would recommend? Any relevant documentation?

Yes, on the target libraries are at /usr/lib/arm-linux-gnueabihf/ and on the host I put them at /lib/arm-clearview/arm-linux-gnueabihf. What’s the problem? The articles I found just say to set CMAKE\_FIND\_ROOT\_PATH to the location. I don’t think I quite follow “setup like a normal Linux root filesystem” or “remove the sysroot prefix”. Doesn’t CMAKE just need to know where to look for the files?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [February 21, 2022, 10:49pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/4 "2022-02-21T22:49:21Z")

</div>

Just copy the files to the sysroot including the path. Your example is a copy of a file without its path.

The keyword is substitution: substitute the sysroot prefix with /. What path do you see now? It should look like on the target.

---

<div class="post-metadata">

### Author: ![nwetter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/c57346/32.png) [@nwetter](https://discourse.cmake.org/u/nwetter)
#### Post date: [February 21, 2022, 11:51pm UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/5 "2022-02-21T23:51:04Z")

</div>

Ok thank you so much for the help–I think I figured out what you meant and what I need to do regarding the sysroot: I’ve taken the entire target filesystem, mounted it on the host, and set CMAKE\_SYSROOT, CMAKE\_PREFIX\_PATH and CMAKE\_FIND\_ROOT\_PATH to the mount location.

One problem I’m having now is that there are symlinks pointing to absolute paths which of course can’t be followed correctly when mounted on the host system. What’s the right way around this? An example:

```auto
CMake Error at /media/nate/sys-1Ah/usr/lib/arm-linux-gnueabihf/cmake/Qt5Gui/Qt5GuiConfig.cmake:27 (message):
  The imported target "Qt5::Gui" references the file

     "/media/nate/sys-1Ah/usr/lib/arm-linux-gnueabihf/libEGL.so"

```

```auto
nate@nate-ubuntuvm:~/hosthome/Documents/GitHub/clearview/cmake-cross$ ls -l /media/nate/sys-1Ah/usr/lib/arm-linux-gnueabihf/libEGL.so
lrwxrwxrwx 1 root root 44 Oct 16 2017 /media/nate/sys-1Ah/usr/lib/arm-linux-gnueabihf/libEGL.so -> /etc/alternatives/arm-linux-gnueabihf_libEGL

```

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [February 22, 2022, 11:54am UTC](https://discourse.cmake.org/t/cross-compiling-to-arm-cmake-cant-find-libraries/5080/6 "2022-02-22T11:54:45Z")

</div>

The Qt5CoreConfig.cmake that I have from Yocto derives the prefix from CMAKE\_CURRENT\_LIST\_DIR

OTOH, you could check if CMAKE\_SYSROOT is available in that context.

Or update it by hand after copying.
