Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5354

C/C++ • Re: CMake and arch-specific compiler options

$
0
0
The ideal case is having a directory (called a sysroot or root filesystem) for each of your targets. They're just normal directories, you can have multiple on the same system.

If you want to target Debian/Ubuntu/Raspberry Pi OS, you can use apt with (s)chroot to install packages into those sysroots. See e.g. https://tttapa.github.io/Pages/Raspberr ... filesystem. I've only ever set this up on Ubuntu, you can definitely do something similar on Raspberry Pi OS, but I don't have any specific instructions, but in broad strokes:
  • Create a directory for your sysroot and install Raspberry Pi OS into it, either by extracting one of the images from the RPi website, or by using the debootstrap script (see the link above).
  • Use (s)chroot to execute apt update/install in that sysroot to install the packages you need.
  • Create a CMake toolchain file that specifies the compiler and points to the sysroot, so the right versions of your libraries are picked up. It is important to use set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) etc. to prevent CMake from trying to locate libraries in /usr/lib of the build system. See the links in my first post for details.
Another option is to use Conan or another package manager. To configure Conan for cross-compilation, you simply provide a "profile" file (https://docs.conan.io/2/tutorial/consum ... conan.html) that specifies the compiler to use, architecture-specific flags, etc. Creating a sysroot is not necessary in this case: Conan will manage versions of packages for different architectures for you, and keep them in separate folders.

Statistics: Posted by tttapa — Sun Aug 25, 2024 6:15 pm



Viewing all articles
Browse latest Browse all 5354

Trending Articles