我几天前尝试使用Dev-Cpp和Windows 10安装opencv,我将.h,.lib和.dll文件的目录添加到Dev-Cpp,但是当我编译代码时,总是给我相同的提示错误。
在编译器选项中,我添加以下目录:
-C++ header -C:\Users\admin\Downloads\opencv\build\include
-图书馆-C:\Users\admin\Downloads\opencv\build\x64\vc15\lib
-二进制文件-C:\Users\admin\Downloads\opencv\build\x64\vc15\bin
-码-
#include <iostream>
#include <opencv2/imgcodecs.hpp>
int main(){
cv::Mat img;
img = cv::imread("Goten.jpg");
return 0;
}
-错误-c:\mingw\mingw32\bin\ld.exe C:\Users\admin\AppData\Local\Temp\cciHfDkS.o:main.cpp:(.text+0x62): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
c:\mingw\mingw32\bin\ld.exe C:\Users\admin\AppData\Local\Temp\cciHfDkS.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to `cv::fastFree(void*)'
c:\mingw\mingw32\bin\ld.exe C:\Users\admin\AppData\Local\Temp\cciHfDkS.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to `cv::Mat::deallocate()'
c:\mingw\mingw32\bin\ld.exe C:\Users\admin\AppData\Local\Temp\cciHfDkS.o:main.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to `cv::fastFree(void*)'
C:\Users\admin\Desktop\Programacion\collect2.exe [Error] ld returned 1 exit status
我已经安装了MinGW 9.2.0,我尝试使用标准C++ 11,C++ 14和C++ 17进行编译我该怎么做才能解决此错误? -对不起,我的英语
最佳答案
这些是链接器错误:这意味着编译器找不到这些函数的二进制代码。
换句话说,您可能忘记指定一些OpenCV库。如果我没记错的话,imread()
驻留在 opencv_imgcodecs 中。
关于c++ - C++:如何在Windows 10上使用编译器MinGW 9.2.0安装OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62543081/