簡體   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