我正在尝试运行一个使用OpenCV的开源程序。我最初遇到undefined reference
个错误,后来变成
在pkg-config搜索路径中找不到软件包opencv
错误,然后又返回到undefined reference
问题。详细信息在后台。还包括编译命令和错误消息。
pkg-config --cflags --libs opencv
。 undefined reference to ...
更改为Package opencv was not found in the pkg-config search path
等。
/usr/local/lib/pkgconfig
,将其包含在某些给定的行中,然后将其他某些给定的行添加到bashrc中。但是,当我创建opencv.pc
文件时,它只是制作了一个名为opencv.pc
的空白文本文件,而不是实际的.pc
文件。此外,即使肯定安装了/usr/local/lib/pkgconfig
,我的计算机上也不存在目录pkg-config
。 我无法使用此解决方案,因此我不断搜索并认为问题的部分原因可能是不是从终端安装OpenCV,而是使用USB密钥从Windows计算机复制了它。因此,我尝试使用以下命令行在终端上安装它:sudo apt-get install libopencv-dev
。
现在我的错误再次是
未定义的引用
尽管在编译命令中我仍然有pkg-config ...
。请注意,不仅OpenCV具有未定义的引用,而且还有我要运行的开源程序特有的文件(它称为“ PuRe”,一种注视眼睛的跟踪算法)。
g++ -I /home/binny/Desktop/opencv/build/include/opencv2/imgcodecs -std=c++11 -I /home/binny/Desktop/example/ -I /home/binny/Desktop/opencv/build/include/ -I /home/binny/Desktop/winrt_x86_msvc2017/include/ -I /home/binny/Desktop/winrt_x86_msvc2017/include/QtCore /home/binny/Desktop/example/main.cpp `pkg-config --cflags --libs opencv
/tmp/ccLpYSrK.o: In function `main':
main.cpp:(.text+0x49): undefined reference to `cv::imread(cv::String const&, int)'
main.cpp:(.text+0x218): undefined reference to `PuRe::PuRe()'
main.cpp:(.text+0x238): undefined reference to `PuRe::run(cv::Mat const&, Pupil&)'
main.cpp:(.text+0x2cd): undefined reference to `cv::ellipse(cv::_InputOutputArray const&, cv::RotatedRect const&, cv::Scalar_<double> const&, int, int)'
main.cpp:(.text+0x322): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text+0x35e): undefined reference to `PuRe::~PuRe()'
main.cpp:(.text+0x484): undefined reference to `PuRe::~PuRe()'
/tmp/ccLpYSrK.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccLpYSrK.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccLpYSrK.o: In function `cv::String::operator=(cv::String const&)':
main.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
答案 0 :(得分:0)
从编译命令看来,您已经将opencv安装到了Desktop文件夹中,而不是安装到了适当的系统文件夹中。这可以正常工作,但会给自动工具pkg-config带来问题,这些工具希望在特定位置查找文件。
如果将PKG_CONFIG_PATH shell变量设置为包括包含opencv.pc文件的文件夹,则可能会有所帮助。
您可以检查是否可以使用
pkg-config --cflags opencv