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 to detect the rest properly:
https://cmake.org/Wiki/CMake_Cross_Co...
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
so, does 3rdparty/lib/libzlib.a exist ? did you have -DBUILD_zlib=ON when building the opencv libs ?
Hi berak thak you for your answer. I check in the 3rdparty/lib/ and it does not exist the libzlib.a. Why happend that?? I only followed the tutorial. You mean in this command include the -DBUILD_zlib=ON in this one: cmake -DBUILD_zlib=ON -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../. somenthing like that?
yes, meant that. think of it as [<some optional parameters>]
and you might need the same for png, jpeg, etc, too.
actually the /3rdparty/lib is empty
I see ok I think that I understand you. I did this: cmake -DBUILD_zlib=ON -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../. and si comming this warning: CMake Warning: Manually-specified variables were not used by the project:
Shall I change something in the arm-gnueabi.toolchain.cmake file?
if that's the build/3rdparty folder, then it's ok. after you ran cmake to rebuild opencv your zlib should end up there.
sorry, it's probably -DBUILD_ZLIB=ON (case sensitive)
thanks it seems that finish ok but when I do the make again it is comming the error. Shall I include the DBUILD option for each folder which are inside of the 3dparty folder?? even 3dparty/lib??
so something like this: cmake -DBUILD_LIB=ON -DBUILD_ZLIB=ON -DBUILD_LIBJASPER=ON -DBUILD_LIBJPEG=ON -DBUILD_LIBPNG=ON -DBUILD_LIBTIFF=ON -DBUILD_LIBWEBP=ON -DBUILD_OPENEXR=ON -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..??
So somenthing like this: cmake -DBUILD_LIB=ON -DBUILD_ZLIB=ON -DBUILD_LIBJPEG=ON-..... DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
"when I do the make again it is comming the error" - for the same lib ? or a different one now ?