Ask Your Question
1

Opencv static link error

asked 2014-06-19 06:15:38 -0500

Jesus gravatar image

updated 2014-09-03 04:20:50 -0500

berak gravatar image

Hi guys I am triying to install the opencv libraries for ARM and I following this tutorial:

 http://docs.opencv.org/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.html

and everything is ok until I try to do the "make", when I execute the make is comming an error:

Linking C static library ../lib/libzlib.a
Error running link command: No such file or directory
make[2]: *** [3rdparty/lib/libzlib.a] Error 2
make[1]: *** [3rdparty/zlib/CMakeFiles/zlib.dir/all] Error 2
make: *** [all] Error 2

someone knows where can be the problem?? it is maybe in the opencv which I download?

Thank you so much

edit retag flag offensive close merge delete

Comments

so, does 3rdparty/lib/libzlib.a exist ? did you have -DBUILD_zlib=ON when building the opencv libs ?

berak gravatar imageberak ( 2014-06-19 06:25:55 -0500 )edit

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?

Jesus gravatar imageJesus ( 2014-06-19 07:04:15 -0500 )edit

yes, meant that. think of it as [<some optional parameters>]

and you might need the same for png, jpeg, etc, too.

berak gravatar imageberak ( 2014-06-19 07:12:24 -0500 )edit

actually the /3rdparty/lib is empty

Jesus gravatar imageJesus ( 2014-06-19 07:16:56 -0500 )edit

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:

BUILD_zlib

Shall I change something in the arm-gnueabi.toolchain.cmake file?

Jesus gravatar imageJesus ( 2014-06-19 07:26:59 -0500 )edit

if that's the build/3rdparty folder, then it's ok. after you ran cmake to rebuild opencv your zlib should end up there.

berak gravatar imageberak ( 2014-06-19 07:29:02 -0500 )edit

sorry, it's probably -DBUILD_ZLIB=ON (case sensitive)

berak gravatar imageberak ( 2014-06-19 07:31:02 -0500 )edit

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 ../../..??

Jesus gravatar imageJesus ( 2014-06-19 07:39:14 -0500 )edit

So somenthing like this: cmake -DBUILD_LIB=ON -DBUILD_ZLIB=ON -DBUILD_LIBJPEG=ON-..... DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..

Jesus gravatar imageJesus ( 2014-06-19 07:44:50 -0500 )edit

"when I do the make again it is comming the error" - for the same lib ? or a different one now ?

berak gravatar imageberak ( 2014-06-19 07:45:36 -0500 )edit

5 answers

Sort by ยป oldest newest most voted
1

answered 2014-09-03 04:06:12 -0500

j gravatar image

any ideas? i get the same error as well... i want to cross compile it for arm on a linux system.

Linking C static library ../lib/libzlib.a Error running link command: No such file or directory make[2]: * [3rdparty/lib/libzlib.a] Error 2 make[1]: [3rdparty/zlib/CMakeFiles/zlib.dir/all] Error 2 make: ** [all] Error 2

when i execute a make command in my builddir/3rdparty/zlib there is the same error...

anybody?

edit flag offensive delete link more

Comments

You will need to install all dependencies of OpenCV first if you want to use them. This can be done simply by the following command:

 sudo apt-get install libtbb-dev libeigen2-dev libqt4-dev libqt4-opengl-dev libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev
StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-03 06:46:16 -0500 )edit

have built static libs (option SHARED_LIBS=OFF) worked for me...

next problem... how to enable gtk support? i have gtk on target system. also on host developement system... unfort. no success. :(

j gravatar imagej ( 2014-09-03 10:43:54 -0500 )edit

add flag -D WITH_GTK=ON and then make sure that all required paths are found correctly.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-04 03:04:43 -0500 )edit

@StevenPuttemans

OpenCV includes source for zlib 1.2.8, https://github.com/opencv/opencv/tree..., so it shouldn't be necessary to use the system provided dev packages.

rhardih gravatar imagerhardih ( 2016-10-27 06:49:26 -0500 )edit

that is only if you select during cmake BUILD_ZLIB. If it detects a system installation, it ignores the shipped versions ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-10-28 04:46:10 -0500 )edit

True enough, but also if the system doesn't have it installed, which is the case for a default Ubuntu for instance. I just tried it out on a stock docker container of ubuntu:16.04 and it seems all the 3rdparty libs are compiled without having to explicitly add any of the -DBUILD_<LIBNAME> flags.

rhardih gravatar imagerhardih ( 2016-10-28 05:47:35 -0500 )edit
0

answered 2015-04-21 05:50:21 -0500

haxan7 gravatar image

I had the same problem.

Make sure that the following line in your arm-gnueabi.toolchain.cmake file is pointing to the correct address

set(ARM_LINUX_SYSROOT /root/work/codesourcery/arm-2013.05 CACHE PATH "ARM cross compilation system root")

edit flag offensive delete link more
0

answered 2016-10-28 05:08:34 -0500

rhardih gravatar image

updated 2016-10-28 05:10:23 -0500

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
edit flag offensive delete link more

Comments

You should ask a new question and give a link to this old post in your new question.

LBerger gravatar imageLBerger ( 2016-10-28 05:18:24 -0500 )edit

Do you have an example I can follow of how best to do it? I'd rather not clutter search results with needless duplications.

rhardih gravatar imagerhardih ( 2016-10-28 05:51:29 -0500 )edit
0

answered 2014-12-04 16:49:38 -0500

OrkunK gravatar image

If we want to cross-compile OpenCV for ARM, OpenCV source files contain some script files for Cmake to create make files

download the OpenCV sources and extract it to where if we want (for example /opt and version 2.4.9) copy the cmake_carma.sh (for ARM with CUDA) from /opt/opencv-2.4.9/platforms/scripts/ to /opt/opencv-2.4.9/platforms/linux/ or change the -DCMAKE_TOOLCHAIN_FILE option (open the scrip file) with ../linux/arm-gnueabi.toolchain.cmake

if we want to change (we may need to change gcc version and cuda toolkit path), add or delete some optional parameters open our copied (.../platforms/linux/cmake_carma.sh) and do what if we want then close

or use cmake_arm_gnueabi_hardfp.sh/cmake_arm_gnueabi_softfp.sh (for ARM without CUDA) then check the toolchain file which is arm-gnueabi.toolchain.cmake at the .../platforms/linux/

we should check gcc and g++ version for just toolchain file

then go to the script file's folder from terminal then type (I used cmake_carma.sh) sudo sh ./cmake_carma.sh and enter it will set build files probably with no error

go to the build folder (which we can see from script files 3rd line) from terminal then

sudo make

we must not use -j<n> option for make (I'm trying it with make errors 6 hours -_- ) when it finish

sudo make install

I've installed by this way just before wrote this.

edit flag offensive delete link more
0

answered 2016-11-01 03:47:07 -0500

AlaaM gravatar image

updated 2016-11-01 07:42:22 -0500

I found a workaround:

After running cmake and generating the make files, edit opencv/opencv/platforms/linux/<your_build_dir>/CMakeFiles/3.5.1/CMakeCCompiler.cmake and replace set(CMAKE_AR "CMAKE_AR-NOTFOUND") with set(CMAKE_AR "/usr/bin/arm-linux-gnueabi-ar")

Note that setting the variable CMAKE_AR in the cmake line (CMAKE_AR="/usr/bin/arm-linux-gnueabi-ar") does not work. Seems like this sets the flag to empty.

edit flag offensive delete link more

Comments

Are you sure you've specified the flag correctly? I used these exact flags, and it worked just fine:

-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

It shouldn't be necessary to edit the generated cmake files by hand.

rhardih gravatar imagerhardih ( 2016-11-01 05:46:59 -0500 )edit

This helped. I have already set my environment variable but ran into the same problem..Why is it needed in the first place?

bot1131357 gravatar imagebot1131357 ( 2017-06-19 21:25:20 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-06-19 06:15:38 -0500

Seen: 7,444 times

Last updated: Nov 01 '16