使用 mingw 编译 opencv3.1

Compile opencv3.1 with mingw

本文关键字:opencv3 编译 mingw 使用      更新时间:2023-10-16

我想用mingw-w64编译以下代码。

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
  Mat im = imread("lena.jpg", 1);
  if (im.empty())
  {
    cout << "Cannot open image!" << endl;
    return -1;
  }
  imshow("image", im);
  waitKey(0);
  return 0;
}

在关注 Windows 7 上的 OpenCV 2.4 和 MinGW 入门之后

我用g++ -I D:opencvbuildinclude -L D:opencvbuildx64vc14lib -lopencv_world310 .loadimg.cpp编译代码

但它返回未定义的引用

C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text+0x40): undefined reference to `cv::imread(cv::String const&, int)'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text+0xb7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text+0xd9): undefined reference to `cv::waitKey(int)'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringC1EPKc[_ZN2cv6StringC1EPKc]+0x4a): undefined reference to `cv::String::allocate(unsigned long long)'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringD1Ev[_ZN2cv6StringD1Ev]+0x11): undefined reference to `cv::String::deallocate()'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x36): undefined reference to `cv::fastFree(void*)'
C:Users1409021AppDataLocalTempcc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x48): undefined reference to `cv::Mat::deallocate()'

该库是 OpenCV3.1,只有一个库opencv_world310

有什么建议吗?

谢谢。

g++ -I D:opencvbuildinclude -L D:opencvbuildx64vc14lib -lopencv_world310 .loadimg.cpp

是错误的。

g++ -I D:opencvbuildinclude -L D:opencvbuildx64vc14lib .loadimg.cpp -lopencv_world310 

是对的。在这里解释