[CMake] Setting library directories when cross-building

Ansis Atteka ansisatteka at gmail.com
Sun Oct 27 22:07:56 EDT 2013


I am building my project on x86_64 system and want to be able to target it for:

1. Local platform (x86_64/Linux); and

2. Remote platform (ARM/Raspberry Pi)

The problem I am encountering is that when I attempt to cross-build
for Raspberry Pi, then linker complains about missing symbols (make
VERBOSE=1 output):

/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
> CMakeFiles/Watson.dir/main.cpp.o -o Watson -L/opt/rpi-rootfs/usr/lib
> -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
> -Wl,-rpath,/opt/rpi-rootfs/usr/lib
> /opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld:
> warning: libz.so.1, needed by /opt/rpi-rootfs/usr/lib/libopencv_core.so,
> not found (try using -rpath or -rpath-link)

...
>
/opt/rpi-rootfs/usr/lib/libopencv_highgui.so: undefined reference to
> `TIFFSetWarningHandler at LIBTIFF_3.9'
> /opt/rpi-rootfs/usr/lib/libopencv_highgui.so: undefined reference to
> `png_read_info at PNG12_0'
> /opt/rpi-rootfs/usr/lib/libopencv_highgui.so: undefined reference to
> `g_time_val_add'
> ...
>
My project depends on OpenCV; and OpenCV depends on libz/libtiff; and
libz/libtiff are in different directories than all opencv libs that I
am using:

/opt/rpi-rootfs/usr/lib/libopencv_core.so
> /opt/rpi-rootfs/usr/lib/arm-linux-gnueabihf/libtiff.so
>
What would be the recommended approach to make linker happy? Maybe
there is a cmake command that could traverse dependencies and add
them? Another solution that seemed to work was to add --sysroot
/opt/rpi-rootfs to the linker arguments. Can I cmake to do that for
me?


This is how my CMakeLists.txt file looks like:

cmake_minimum_required(VERSION 2.8)
>
> project(watson)
> find_package(OpenCV REQUIRED)
> add_executable(Watson main.cpp)
> target_link_libraries(Watson ${OpenCV_LIBS})
>
This is how my CMAKE_TOOLCHAIN_FILE for Raspberry Pi looks like:

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)
>
/lib and /usr directories from Raspberry Pi are rsync'ed to
/opt/rpi-rootfs on my x86_64 system.

Best regards,
Ansis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20131027/7a708ff4/attachment.htm>


More information about the CMake mailing list