简体   繁体   English

ld找不到opencv highgui符号(未定义参考)

[英]ld can't find opencv highgui symbols (undefined reference)

I have a program correctly compiling and working on a machine and I'm trying to run it on another similar machine: same OS (Debian Stretch), same related packages installed, and same version of opencv (libopencv-dev version: 2.4.9.1+dfsg-2). 我有一个可以在计算机上正确编译和运行的程序,并且试图在另一台类似的计算机上运行它:相同的OS(Debian Stretch),安装的相同相关软件包以及相同版本的opencv(libopencv-dev版本:2.4.9.1) + dfsg-2)。 However, on the second machine, ld fails to link opencv highgui symbols: 但是,在第二台计算机上,ld无法链接opencv highgui符号:

$ g++ $(pkg-config --cflags opencv) SDLTest.c $(pkg-config --libs opencv) -l pthread -L/usr/lib/x86_64-linux-gnu -lSDL
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -O3 /tmp/ccbTuxi1.o : Dans la fonction « opencv_calibrate(cv::VideoCapture) » :
SDLTest.c:(.text+0x33d3) : référence indéfinie vers « cv::namedWindow(std::string const&, int) »
SDLTest.c:(.text+0x3416) : référence indéfinie vers « cv::setMouseCallback(std::string const&, void (*)(int, int, int, int, void*), void*) »
SDLTest.c:(.text+0x3570) : référence indéfinie vers « cv::imshow(std::string const&, cv::_InputArray const&) »
SDLTest.c:(.text+0x36e0) : référence indéfinie vers « cv::destroyWindow(std::string const&) » collect2: error: ld returned
1 exit status

All corresponding packages are installed (libopencv-* and libhighgui-*). 安装了所有相应的软件包(libopencv- *和libhighgui- *)。 ldconfig finds the .so file: ldconfig查找.so文件:

$ sudo ldconfig -v 2>/dev/null | grep highgui   libopencv_highgui.so.2.4
-> libopencv_highgui.so.2.4.9

and the file exists: 并且文件存在:

$ locate libopencv_highgui.so.2.4.9
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9

There are many references to opencv throughout the code, but for some reason the highgui functions are the only one to create trouble. 整个代码中都有很多对opencv的引用,但是由于某些原因,highgui函数是唯一会引起麻烦的函数。

In my code, I include the C headers (which for some reason work for including the C++ API): 在我的代码中,我包含了C头文件(出于某些原因,它们可以包含C ++ API):

#include <cv.h>
#include <cvaux.h>
#include <highgui.h>

and using the C++ headers instead does not change anything. 而使用C ++标头则不会更改任何内容。

I'm out of ideas. 我没主意了。 Any idea? 任何想法?

Edit: Output of pkg-config --libs opencv: 编辑:pkg-config --libs opencv的输出:

/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab

因此,我最终在QT支持下自己编译了opencv来解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM