开发者

OpenCV static linking error

开发者 https://www.devze.com 2023-04-09 04:47 出处:网络
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 s开发者_StackOverflow中文版ee all the dependencies.

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 s开发者_StackOverflow中文版ee 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消