【发布时间】:2019-09-25 23:41:48
【问题描述】:
我正在尝试运行一个使用 OpenCV 等的开源程序。我最初遇到了 undefined reference 错误,它变成了
在 pkg-config 搜索路径中找不到包 opencv
然后返回到undefined reference 问题的错误。细节在后台。编译命令和错误信息也包括在内。
- 我的初始错误是一长串“未定义引用”错误。我无法解决它,但注意到这个StackOverflow question,如果我在 Ubuntu 而不是 Windows 上尝试它,我可以尝试添加
pkg-config --cflags --libs opencv。 - 然后我的编译错误从
undefined reference to ...变为Package opencv was not found in the pkg-config search path等。- 接受的解决方案 (StackOverflow question) 似乎是创建一个名为 opencv.pc 的文件,将其复制到
/usr/local/lib/pkgconfig,将其包含在某些给定的行中,然后将其他一些给定的行添加到 bashrc。但是,当我创建opencv.pc文件时,它只是创建了一个名为opencv.pc的空白文本文件,而不是实际的.pc文件。此外,/usr/local/lib/pkgconfig目录在我的计算机上不存在,即使pkg-config肯定已安装。
- 接受的解决方案 (StackOverflow question) 似乎是创建一个名为 opencv.pc 的文件,将其复制到
-
我无法让这个解决方案发挥作用,所以我一直在搜索,并认为问题的一部分可能是我没有从终端安装 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
【问题讨论】: