voodoo16 voodoo16 - 2 months ago 12
C Question

Cross compiling for raspberryPi -- including libraries from synchronized filesystem

I am trying to cross compile simple project on my PC to get working on RaspberryPi. I found some tutorials on web and made cmake file. Basic cmake file work on rpi side, but cross compile additional file have some problems. Makefiles are generated properly, but invoking

make
throws out that it can't find
wiringPi.h
library, which ofc I am using. I have synchronized /lib and /usr from rpi to my pc.

Here is my cmake for cross compilation.

#info
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compilers
SET(CMAKE_C_COMPILER
/home/voodoo16/raspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER
/home/voodoo16/raspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /home/voodoo16/raspberryPi/fs)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


Of course I invoke cmake creation via:

cmake -DCMAKE_TOOLCHAIN_FILE=crossCompile.cmake .


Files exist in fs folder. Here is output of find:

voodoo16@tesla:[~/raspberryPi/fs]$ find -name *wiringPi*
./usr/local/include/wiringPiSPI.h
./usr/local/include/wiringPi.h
./usr/local/include/wiringPiI2C.h
./usr/local/lib/libwiringPi.so
./usr/local/lib/libwiringPi.so.2.32
./usr/local/lib/libwiringPiDev.so
./usr/local/lib/libwiringPiDev.so.2.32
./usr/lib/libwiringPi.so
./usr/lib/libwiringPiDev.so


I suppose that I'm missing some cmake command which allows to see libraries from rpi filesystem not via pc system using standard
#include <lib.h>
.

Best regards,
voodoo16.

Answer

You need to set CMake variable CMAKE_SYSROOT for hint compiler about cross compilation:

set(CMAKE_SYSROOT "/home/voodoo16/raspberryPi/fs")

CMake variables CMAKE_FIND_* affects only on CMake find_* commands, they don't directly hint the compiler. From the other side, CMAKE_SYSROOT variable hints for find_* commands too.