Student4K
Student4K

Reputation: 951

Crosscompiling with cmake for ARM with OpenCV

I am trying to crosscompile my application, written in C++ and using OpenCV for BeagleBone ARM-based board. The target OS is Ubuntu 13.10, the host OS is Ubuntu 12.04 and I can build the app successfully on the both systems using native compiler. However, when I crosscompile using arm cross compiler from Ubuntu repository, I get an error about missing standard header file (bits/stdlib-float.h). Here is a small example to show the same problem (arm_root directory contains the target environment).

src/cross.cpp:

#include <opencv2/opencv.hpp>

int main()
{
    cv::Mat m(10, 10, CV_8UC1);
    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
find_package(OpenCV REQUIRED)
add_executable(cross src/cross.cpp)
target_link_libraries(cross ${OpenCV_LIBS})

arm_toolchain.cmake (The idea is to link the app to the standard C++ library in the host crosscompiler environment, but link to the OpenCV in the target environment. I am not sure whether this is a right choice):

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabihf /home/alex/arm_root)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

cmake -DCMAKE_TOOLCHAIN_FILE=../arm_toolchain.cmake .. && make:

[100%] Building CXX object CMakeFiles/cross.dir/src/cross.cpp.o
In file included from /home/alex/arm_root/usr/include/opencv2/core/types_c.h:56:0,
                 from /home/alex/arm_root/usr/include/opencv2/core/core_c.h:47,
                 from /home/alex/arm_root/usr/include/opencv2/opencv.hpp:46,
                 from /home/alex/sandbox/cmake/cross/src/cross.cpp:1:
/home/alex/arm_root/usr/include/stdlib.h:951:31: fatal error: bits/stdlib-float.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/cross.dir/src/cross.cpp.o] Error 1
make[1]: *** [CMakeFiles/cross.dir/all] Error 2
make: *** [all] Error 2

Upvotes: 2

Views: 3423

Answers (2)

Jose Luis C.D.
Jose Luis C.D.

Reputation: 21

It is an include path problem: bits directory doesn't exist on ${SYSROOT}/usr/include (${SYSROOT} is where your board's sysroot lives). It's located at ${SYSROOT}/usr/include/arm-linux-gnueabihf.

Add the following lines to your toolchain file and it will work:

    set(CMAKE_SYSROOT ${RASPI_SYSROOT})
    include_directories(${RASPI_SYSROOT}/usr/include/arm-linux-gnueabihf)

Upvotes: 2

jasal
jasal

Reputation: 1053

Does the file /home/alex/arm_root/usr/include/bits/stdlib-float.h exist? Make sure you are using the correct include directory. In some toolchains there are multiple include directories. Try to add the following line to your toolchain definition file:

set(CMAKE_CXX_FLAGS "-isystem /home/alex/arm_root/usr/include")

or whatever directory the required include files are in. This will make sure the compiler uses the correct path for the standard headers.

Upvotes: 1

Related Questions