简体   繁体   中英

How to cross compile Raspberry Pi project on x86_64? (missing *.so due to invalid path)

I am cross compiling Raspberry Pi project on x86_64/Ubuntu 13.04. After invoking cmake with:

cmake -DCMAKE_TOOLCHAIN_FILE=./Toolchain-raspberry.pi .

and then make , linking fails:

/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lopencv_gpu
...

The problem is that cmake generated Makefile invokes linker in the following way:

/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++       CMakeFiles/Watson.dir/main.cpp.o  -o Watson -rdynamic -lopencv_gpu -lopencv_contrib -lopencv_legacy -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core 

and it does not specify paths to those shared libraries. However, if I manually add --sysroot /opt/rpi-rootfs/ flag to the command above, then linking succeeds.

What is the recommended way to get cmake to specify the right paths to the shared libraries when cross compiling?

Here is my Toolchain-raspberry.pi file:

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_C_COMPILER /opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)

SET(CMAKE_FIND_ROOT_PATH "/opt/rpi-rootfs/")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

And this is my CMakeList.txt file:

cmake_minimum_required(VERSION 2.8)

project(watson)
add_executable(Watson main.cpp)

find_package(OpenCV REQUIRED)
target_link_libraries(Watson ${OpenCV_LIBS})

The /usr and /lib directories from the target are rsync'ed to /opt/rpi-rootfs/ and all the necessary *.so files are there. After reading cmake documentation, I would have expected that setting CMAKE_FIND_ROOT_PATH would solve this problem, but apparently not. I am using cmake version 2.8.10.1.

By my pratice,

INCLUDE_DIRECTORIES(/opt/rpi-rootfs/usr/include)
LINK_DIRECTORIES(
    /opt/rpi-rootfs/usr/lib
    /opt/rpi-rootfs/lib
)

will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM