OpenCV static linking error

青春壹個敷衍的年華 提交于 2019-12-08 05:38:07

问题


I want to use OpenCV as a static library. After compiling the library as a static library now i'm testing with some examples to see all the dependencies.

The dependencies added to compile are -staticpkg-config --libs opencv-lpthread -ljpeg -ltiff -lz -ljasper -lpng12

But obtain the following Error message:

g++ -c -g -Wall -O2 `pkg-config --cflags opencv` formas.cpp 
g++ -g -Wall -O2 `pkg-config --cflags opencv` formas.o -o paint -static `pkg-config --libs opencv` -lpthread -ljpeg -ltiff -lz -ljasper -lpng12 
/usr/local/lib/libopencv_core.a(system.o): In function `cv::tempfile(char const*)': 
system.cpp:(.text._ZN2cv8tempfileEPKc+0x3a): warning: the use of `tmpnam' is dangerous, better use `mkstemp' 
/usr/local/lib/libopencv_core.a(system.o): In function `cv::getTickCount()': 
system.cpp:(.text._ZN2cv12getTickCountEv+0x2a): undefined reference to `clock_gettime' 
/usr/local/lib/libopencv_highgui.a(grfmt_png.o): In function `cv::PngDecoder::readHeader()': 
grfmt_png.cpp:(.text._ZN2cv10PngDecoder10readHeaderEv+0xde): undefined reference to `png_set_longjmp_fn' 
/usr/local/lib/libopencv_highgui.a(grfmt_png.o): In function `cv::PngEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)': 
grfmt_png.cpp:(.text._ZN2cv10PngEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x134): undefined reference to `png_set_longjmp_fn' 
/usr/local/lib/libopencv_highgui.a(grfmt_png.o): In function `cv::PngDecoder::readData(cv::Mat&)': 
grfmt_png.cpp:(.text._ZN2cv10PngDecoder8readDataERNS_3MatE+0x141): undefined reference to `png_set_longjmp_fn' 
collect2: ld returned 1 exit status 
make: *** [all] Error 1

I made something wrong or there an error in OpenCV library.

OpenCV version: 2.3.1 (latest version) formas --> example which create an image an draw some figures and save into a file. So simple.

Thanks in advance.


回答1:


It seems you have compiled OpenCV with libpng 1.4 or newer but trying to link with libpng 1.2

What cmake command have you used to configure OpenCV?

Update:

You need to add -lrt to the list of libraries you link for the clock_gettime function.



来源:https://stackoverflow.com/questions/7603777/opencv-static-linking-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!