我试图在Windows 7上使用OpenCV 4.11和当前版本的Mingw编译简单程序。我从https://github.com/huihut/OpenCV-MinGW-Build下载了OpenCV的二进制文件。我试图使用命令来编译它: “ g ++ main.cpp -std = c ++ 11 -IF:\ cpp_tools \ libs \ OpenCV-MinGW-Build-OpenCV-4.1.1-x64 \ include -LF:\ cpp_tools \ libs \ OpenCV-MinGW-Build-OpenCV -4.1.1-x64 \ x64 \ mingw \ lib -lopencv_core411.dll -lopencv_imgcodecs411.dll -lopencv_imgproc411.dll -lopencv_highgui411.dll -o myprog.exe“
我得到了链接器错误:
C:\ Users \ Radek \ AppData \ Local \ Temp \ ccyTSmo1.o:main.cpp :(。text + 0xa0):未定义
对cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x13e): undefined r
eference to
cv :: namedWindow(std :: __ cxx11 :: basic_string,std :: allocator> const&,int)的引用)”
C:\ Users \ Radek \ AppData \ Local \ Temp \ ccyTSmo1.o:main.cpp :(。text + 0x19f):未定义
cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, cv::_InputArray const&)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text+0x1c9): undefined r
eference to
cv :: waitKey(int)'的引用
C:\ Users \ Radek \ AppData \ Local \ Temp \ ccyTSmo1.o:main.cpp :(。text $ _ZN2cv3MatD1Ev [__ ZN
2cv3MatD1Ev] + 0x2d):对cv::fastFree(void*)'
C:\Users\Radek\AppData\Local\Temp\ccyTSmo1.o:main.cpp:(.text$_ZN2cv3Mat7releaseE
v[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to
cv :: Mat :: deallocate()'的未定义引用
C:\ Users \ Radek \ AppData \ Local \ Temp \ ccyTSmo1.o:main.cpp :(。text $ ZN2cv3MataSEOS0 [_
ZN2cv3MataSEOS0 ] + 0xb4):对`cv :: fastFree(void *)'的未定义引用
collect2.exe:错误:ld返回1退出状态
我阅读了很多类似的问题,但是都没有解决我的问题。
源代码:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
String imageName( "../data/HappyFish.jpg" ); // by default
if( argc > 1)
{
imageName = argv[1];
}
Mat image;
image = imread( imageName, IMREAD_COLOR ); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
waitKey(0); // Wait for a keystroke in the window
return 0;
}
答案 0 :(得分:0)
应该不是
g++ main.cpp -std=c++11 -I F:\cpp_tools\libs\OpenCV-MinGW-
Build-OpenCV-4.1.1-x64\include -L F:\cpp_tools\libs\OpenCV-
MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\lib
-llibopencv_core411 -llibopencv_imgcodecs411
-llibopencv_imgproc411 -llibopencv_highgui411 -o
myprog.exe
用-llibopencv
而不是-lopencv
?
您是否尝试过GitHub上提到的帮助Running a C++ program with OpenCV 3.4.1 using MinGW-w64 g++ in Visual Studio Code on Windows 10 x64?