繁体   English   中英

如何解决opencv'undefined reference'编译问题,当pkg-config无法解决时?

[英]How to resolve opencv 'undefined reference' compilation problem, when pkg-config doesn't solve it?

我正在尝试运行一个开源程序,其中包括OpenCV。 我最初遇到了undefined reference错误,它们变成了

在pkg-config搜索路径中找不到包opencv

然后返回到undefined reference问题的错误。 细节在后台。 还包括编译命令和错误消息。

  • 我的初始错误是一个很长的“未定义引用”错误列表。 我无法解决它,但注意到,这个StackOverflow问题 ,如果我在Ubuntu而不是Windows上尝试它,我可以尝试添加pkg-config --cflags --libs opencv
  • 然后我的编译错误从未undefined reference to ...更改undefined reference to ...Package opencv was not found in the pkg-config search path等。
    • 接受的解决方案( StackOverflow问题 )似乎是创建一个名为opencv.pc的文件,将其复制到/usr/local/lib/pkgconfig ,将其包含在某些给定的行中,然后将其他一些给定的行添加到bashrc中。 但是,当我创建opencv.pc文件时,它只是创建了一个名为opencv.pc的空白文本文件,而不是实际的.pc文件。 此外,即使安装了pkg-config ,我的计算机上也不存在目录/usr/local/lib/pkgconfig
  • 我无法让这个解决方案起作用,所以我一直在搜索并认为问题的一部分可能是从终端安装OpenCV而不是从我的Windows计算机上用USB密钥复制它。 所以我尝试使用这一行在终端上安装它: 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

从编译命令看来,您已将opencv安装到Desktop文件夹中,而不是安装到相应的系统文件夹中。 这将起作用,但会为像pkg-config这样的自动工具带来问题,这些工具希望在特定的地方找到它们的文件。

如果将PKG_CONFIG_PATH shell变量设置为包含包含opencv.pc文件的文件夹,则可能会有所帮助。

您可以检查这是否有效

pkg-config --cflags opencv

暂无
暂无

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

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