Ask Your Question
0

unable to link static opencv

asked 2015-05-06 18:40:38 -0600

theodore gravatar image

I have compiled successfully the new rc version of opencv with the static libraries enabled. However, when I am trying to link my application to these libraries I am getting a many errors:

....
....
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::crossCorr(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Size_<int>, int, cv::Point_<int>, double, int)':
(.text._ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x5a2): undefined reference to `cv::getOptimalDFTSize(int)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::crossCorr(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Size_<int>, int, cv::Point_<int>, double, int)':
(.text._ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0xe81): undefined reference to `cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::crossCorr(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Size_<int>, int, cv::Point_<int>, double, int)':
(.text._ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1a2a): undefined reference to `cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::crossCorr(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Size_<int>, int, cv::Point_<int>, double, int)':
(.text._ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1b01): undefined reference to `cv::mulSpectrums(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, bool)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::crossCorr(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Size_<int>, int, cv::Point_<int>, double, int)':
(.text._ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1b62): undefined reference to `cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplateMask(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&)':
(.text._ZN2cvL17matchTemplateMaskERKNS_11_InputArrayES2_RKNS_12_OutputArrayEiS2_+0x2835): undefined reference to `cv::sqrt(cv::_InputArray const&, cv::_OutputArray const&)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplate(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&)':
(.text._ZN2cv13matchTemplateERKNS_11_InputArrayES2_RKNS_12_OutputArrayEiS2_+0x1e80): undefined reference to `ippicviCrossCorrNorm_8u32f_C1R'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplate(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&)':
(.text._ZN2cv13matchTemplateERKNS_11_InputArrayES2_RKNS_12_OutputArrayEiS2_+0x1e9e): undefined reference to `ippicviCrossCorrNormGetBufferSize'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplate(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&)':
(.text._ZN2cv13matchTemplateERKNS_11_InputArrayES2_RKNS_12_OutputArrayEiS2_+0x1ead): undefined reference to `ippicvsMalloc_8u'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplate(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&)':
(.text._ZN2cv13matchTemplateERKNS_11_InputArrayES2_RKNS_12_OutputArrayEiS2_+0x1efd): undefined reference to `ippicvsFree'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib/libopencv_imgproc.a(templmatch.cpp.o): In function `cv::matchTemplate(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray ...
(more)
edit retag flag offensive close merge delete

Comments

can you show your makefile, or whatever you're using ?

with static linking, the order of libs is important (stuff like zlib or core, which are referenced from other libs, has to go at the end of the list)

berak gravatar imageberak ( 2015-05-07 04:18:48 -0600 )edit

@berak I am trying to compile the application with the following command g++ -o app main.cpp 'pkg-config --static --cflags --libs opencv'. I did not know that there should be a specific order of the linked libs. Do you know if there is any sample somewhere of how the libs should be ordered, which I can use.

theodore gravatar imagetheodore ( 2015-05-07 05:18:27 -0600 )edit

if you do pkg-config --static --cflags --libs opencv on the console, what is the outcome ?

berak gravatar imageberak ( 2015-05-07 05:28:24 -0600 )edit

this one:

-I/usr/include/opencv -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_hal -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab -lopencv_viz -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_face -lopencv_latentsvm -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto

theodore gravatar imagetheodore ( 2015-05-07 05:59:56 -0600 )edit

what happens, if you do it manually, and move core and imgproc to the end of the list ? i got: g++ -std=c++0x cv.cpp -I ocv3/include -L ocv3/lib -L ocv3/share/OpenCV/3rdparty/lib -lopencv_imgcodecs -lopencv_calib3d -lopencv_ccalib -lopencv_xfeatures2d -lopencv_features2d -lopencv_xobjdetect -lopencv_flann -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_xphoto -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_bgsegm -lopencv_face -lopencv_saliency -lopencv_stitching -lopencv_superres -lopencv_tracking -lopencv_ximgproc -lopencv_shape -lopencv_text -lopencv_optflow -lopencv_reg -lopencv_bioinspired -lopencv_imgproc -lopencv_core -lopencv_hal -ljpeg -llibpng -llibtiff -llibwebp -lippicv -lrt -ldl -lz -lpthread -o cv

berak gravatar imageberak ( 2015-05-07 06:58:44 -0600 )edit

@berak nope same output. Is it compiling in your case?

theodore gravatar imagetheodore ( 2015-05-07 08:44:03 -0600 )edit

it does not seem to find any of the 3rd party libs on your side

berak gravatar imageberak ( 2015-05-07 08:49:32 -0600 )edit

just trying with ipp, trouble there atm

berak gravatar imageberak ( 2015-05-07 08:50:03 -0600 )edit

compiles now. edited the comment above with current state.

libippicv is in -L ocv3/share/OpenCV/3rdparty/lib

http://sugarcoatedchili.herokuapp.com...

berak gravatar imageberak ( 2015-05-07 08:53:12 -0600 )edit

I added: -L/usr/share/opencv/3rdparty/lib -lippicv same issues. Btw it does not find the following libs as well /usr/bin/ld: cannot find -llibpng /usr/bin/ld: cannot find -llibtiff /usr/bin/ld: cannot find -llibwebp

theodore gravatar imagetheodore ( 2015-05-07 08:54:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-05-07 18:32:21 -0600

theodore gravatar image

updated 2015-05-07 18:35:17 -0600

ok after a lot of trial and error debugging procedures (many thanks @berak for his help and his time) the following seems to do the trick:

g++ -o application main.cpp -I/usr/include/opencv -L/usr/lib -L/usr/share/opencv/3rdparty/lib -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_imgproc -lopencv_core -lopencv_hal -lopencv_highgui -lopencv_imgcodecs -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab -lopencv_viz -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_face -lopencv_latentsvm -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto -llibjpeg -llibpng -llibtiff -lippicv -lrt -ldl -lwebp -lz -lzlib -llibjasper -lQtGui -lQtCore -lQtOpenGL -lQtTest -lGL -lGLU -lglut -ltbb -lpthread

bear in mind that you need to have enabled the -DBUILD_ZLIB=ON -DBUILD_TIFF=ON -DBUILD_JASPER=ON -DBUILD_JPEG=ON -DBUILD_PNG=ON -DBUILD_TBB=ON flags during the opencv build otherwise you will need to use the -ljpeg -lpng -ltiff -ljasper instead. Unfortunately I did not manage to make OpenEXR to work so you will need to have -DBUILD_OPENEXR=OFF and -DWITH_OPENEXR=OFF flags as well. If you have build opencv with IPP, Qt and OpenGL as in my case then you will need the -lippicv -lQtGui -lQtCore -lQtOpenGL -lQtTest -lGL -lGLU -lglut respectively. Otherwise you do not need to include these libs.

Hope it helps, now and in the future someone.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-06 18:40:38 -0600

Seen: 3,729 times

Last updated: May 07 '15