Cross compiling to ARM, CMAKE can't find libraries

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:

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_PREFIX_PATH /lib/arm-clearview/arm-linux-gnueabihf)
set(CMAKE_SYSROOT /lib/arm-clearview/arm-linux-gnueabihf)

Full output from CMAKE can be seen here.

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:

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

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 /.

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?

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.

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:

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

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

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.