I am getting into cross-compiling (raspberry Pi stuff), and although I've been reading a bunch of tutorials, I still don't get it.
Here is a typical toolchain.cmake
file, as described in most of these examples:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
set(CMAKE_STAGING_PREFIX /home/devel/stage)
set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
My first question: why do I even need a toolchain in the first place? Reading some other threads, cross-compilers are just compilers that can target a different platform (e.g. I have a specific x86-64 machine, but I am asking my compiler to generate arm instructions for a different machine with a different set of registers). Can't I just pass -DCMAKE_CXX_COMPILER=/../arm-linux-gnueabihf-g++
and some -march
options to CMake and call it a day?
Assuming I really need the toolchain file shown above, why would I need all these CMAKE_FIND_ROOT_PATH_MODE_
commands? I thought the whole point of cross-compiling was that the entire compilation process would take place on my host computer, and I would only need to copy the executable to the target machine. I understand it will need to find some .dlls on the target system (which I assume is what the CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
option is for), but why would it need to find headers there?