Surcouf
Posts: 16
Joined: Sat Dec 09, 2017 12:23 pm

Correct workflow for cross compilation and 3rd party libraries

Sat Sep 30, 2023 12:34 pm

I want to cross compile cmatrix app for raspberry pi, using crosstool-ng toolchain on desktop ubuntu. I am using cmake workflow for this, I created following cmake toolchain file based on cmake docs:

Code: Select all

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER   aarch64-rpi4-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-rpi4-linux-gnu-g++)

# where is the target environment located
set(CMAKE_FIND_ROOT_PATH  /workdir/crosstool-ng/x-tools/aarch64-rpi4-linux-gnu)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Then, to compile I use:

Code: Select all

mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cross.cmake ..
This fails since cmake cannot find ncurses library:

Code: Select all

-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) 
-- Looking for use_default_colors
-- Looking for use_default_colors - not found
After that I tried “hacking” it by installing ncurses on target (RPi 4), copying .so files to the build machine from rootfs and trying to link it, but it resulted in more errors. Also this seemed like not the right way to go about it.

What is the correct workflow here? Basically, I have an application that uses external library (ncurses) and I want to cross compile it for another architecture.

Refs:
https://github.com/abishekvashok/cmatrix
https://cmake.org/cmake/help/book/maste ... CMake.html

User avatar
dickon
Posts: 2516
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, in Tiffield

Re: Correct workflow for cross compilation and 3rd party libraries

Sat Sep 30, 2023 1:42 pm

This is a complicated thing to do from scratch, and I'd recommend looking into buildroot or similar rather than trying to roll your own. Is that CMAKE_FIND_ROOT_PATH pointing at a full root filesystem, or just the bits that gcc and friends need?
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

Return to “Advanced users”