I want to cross-compile c++ code for my raspberry-pi on my notebook (Ubuntu 18.04) and I spent hours and it still doesn't work. I followed this little tutorial and it's working. I want to link against the eclipse paho-mqtt-c++ lib, which I installed on my raspberry. I did rsync with my raspberry as in the tutorial, I now have a rootfs folder and there under rootfs/usr/local/include/ the header files for using the lib are stored and the lib itself is under rootfs/usr/local/lib.
My toolchain cmake file contains the following:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER $ENV{HOME}/applications/raspberry-tools/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/applications/raspberry-tools/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
#SET(CMAKE_SYSROOT /home/manuelhoffmann/applications/raspberry-tools/rootfs)
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/applications/raspberry-tools/rootfs)
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
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)
#SET(CMAKE_LIBRARY_PATH /home/manuelhoffmann/applications/raspberry-tools/rootfs/usr/local/lib)
include_directories(${CMAKE_FIND_ROOT_PATH}/usr/local/include)
#INCLUDE_DIRECTORIES($ENV{HOME}/applications/raspberry-tools/rootfs/usr/local/include)
#link_directories(${CMAKE_FIND_ROOT_PATH}/usr/local/lib)
#find_library(${CMAKE_FIND_ROOT_PATH}/usr/local/lib)
add_definitions(-Wall -std=c11)
The include_directories was necessary so that it finds the headers and now it is compiling fine. But it still has a problem when linking, the output is:
raspberry-tools/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -pthread CMakeFiles/kg_iot_gateway.dir/gateway.cpp.o CMakeFiles/kg_iot_gateway.dir/MQTTClient.cpp.o CMakeFiles/kg_iot_gateway.dir/socket.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MessageGWInfo.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MessagePublish.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MQTTSNFlags.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MQTTSNMessage.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MQTTSNMessageHeader.cpp.o CMakeFiles/kg_iot_gateway.dir/snmessage/MQTTSNMessageVariablePart.cpp.o CMakeFiles/kg_iot_gateway.dir/main.cpp.o -o kg_iot_gateway -lpaho-mqttpp3
/applications/raspberry-tools/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.5.0/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lpaho-mqttpp3
collect2: error: ld returned 1 exit status
CMakeFiles/kg_iot_gateway.dir/build.make:218: recipe for target 'kg_iot_gateway' failed
make[2]: *** [kg_iot_gateway] Error 1
make[2]: Leaving directory '/kg-iot-gateway/build'
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/kg_iot_gateway.dir/all' failed
make[1]: *** [CMakeFiles/kg_iot_gateway.dir/all] Error 2
make[1]: Leaving directory '/kg-iot-gateway/build'
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
All commented lines didn't work or bring the desired result.
So how can I tell cmake to look for libs also in rootfs/usr/local/lib? What am I doing wrong?
Thanks for helping!