Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I ran into this very same problem and from what I could gather, it seems CMake doesn't correctly detect binaries for cross-compilation, even though it's indicated in the wiki, that just setting the compiler via the CC env variable, should be enough detect the rest properly:

https://cmake.org/Wiki/CMake_Cross_Compiling

In my case I've installed gcc-arm-linux-gnueabihf and g++-arm-linux-gnueabihf, which has the corresponding binutils as dependencies, so you get the correct linker etc.

However, just running the gnueabihf script in /opencv/platforms/scripts/cmake_arm_gnueabi_hardfp.sh, specifying the correct C and CXX compilers was not enough, since CMake didn't find the gnueabihf version of ar to use:

# ./cmake_arm_gnueabi_hardfp.sh -D CMAKE_C_COMPILER=/usr/bin/arm-linux gnueabihf-gcc -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++

# cat ../build_linux_arm_hardfp/CMakeVars.txt | grep CMAKE_AR
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_CXX_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_CXX_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_CXX_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_CXX_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>

Which results in the following linker command for zlib:

# cat 3rdparty/zlib/CMakeFiles/zlib.dir/link.txt
CMAKE_AR-NOTFOUND qc ../lib/libzlib.a  CMakeFiles/zlib.dir/adler32.c.o CMakeFiles/zlib.dir/compress.c.o CMakeFiles/zlib.dir/crc32.c.o CMakeFiles/zlib.dir/deflate.c.o CMakeFiles/zlib.dir/gzclose.c.o CMakeFiles/zlib.dir/gzlib.c.o CMakeFiles/zlib.dir/gzread.c.o CMakeFiles/zlib.dir/gzwrite.c.o CMakeFiles/zlib.dir/inflate.c.o CMakeFiles/zlib.dir/infback.c.o CMakeFiles/zlib.dir/inftrees.c.o CMakeFiles/zlib.dir/inffast.c.o CMakeFiles/zlib.dir/trees.c.o CMakeFiles/zlib.dir/uncompr.c.o CMakeFiles/zlib.dir/zutil.c.o

So in order to fix it, set the path to ar explicitly, as with the compiler versions:

# ./cmake_arm_gnueabi_hardfp.sh -D CMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ -DCMAKE_AR=/usr/bin/arm-linux-gnueabihf-ar

I ran into this very same problem and from what I could gather, it seems CMake doesn't correctly detect binaries for cross-compilation, even though it's indicated in the wiki, that just setting the compiler via the CC CC env variable, should be enough to detect the rest properly:

https://cmake.org/Wiki/CMake_Cross_Compiling

In my case I've installed gcc-arm-linux-gnueabihf and g++-arm-linux-gnueabihf, which has the corresponding binutils as dependencies, so you get the correct linker etc.

However, just running the gnueabihf script in /opencv/platforms/scripts/cmake_arm_gnueabi_hardfp.sh, specifying the correct C and CXX compilers was not enough, since CMake didn't find the gnueabihf version of ar to use:

# ./cmake_arm_gnueabi_hardfp.sh -D CMAKE_C_COMPILER=/usr/bin/arm-linux gnueabihf-gcc -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++

# cat ../build_linux_arm_hardfp/CMakeVars.txt | grep CMAKE_AR
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_CXX_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_CXX_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_AR=CMAKE_AR-NOTFOUND
CMAKE_CXX_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_CXX_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_APPEND=<CMAKE_AR> q  <TARGET> <LINK_FLAGS> <OBJECTS>
CMAKE_C_ARCHIVE_CREATE=<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>

Which results in the following linker command for zlib:

# cat 3rdparty/zlib/CMakeFiles/zlib.dir/link.txt
CMAKE_AR-NOTFOUND qc ../lib/libzlib.a  CMakeFiles/zlib.dir/adler32.c.o CMakeFiles/zlib.dir/compress.c.o CMakeFiles/zlib.dir/crc32.c.o CMakeFiles/zlib.dir/deflate.c.o CMakeFiles/zlib.dir/gzclose.c.o CMakeFiles/zlib.dir/gzlib.c.o CMakeFiles/zlib.dir/gzread.c.o CMakeFiles/zlib.dir/gzwrite.c.o CMakeFiles/zlib.dir/inflate.c.o CMakeFiles/zlib.dir/infback.c.o CMakeFiles/zlib.dir/inftrees.c.o CMakeFiles/zlib.dir/inffast.c.o CMakeFiles/zlib.dir/trees.c.o CMakeFiles/zlib.dir/uncompr.c.o CMakeFiles/zlib.dir/zutil.c.o

So in order to fix it, set the path to ar explicitly, as with the compiler versions:

# ./cmake_arm_gnueabi_hardfp.sh -D CMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ -DCMAKE_AR=/usr/bin/arm-linux-gnueabihf-ar