在 Eclipse 中使用 opencv 2.4.10 编译代码

Compiling the code with opencv 2.4.10 in Eclipse

本文关键字:编译 代码 opencv Eclipse      更新时间:2023-10-16

编译下面的代码后,我发现错误如下所述。

#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );
  if( argc != 2 || !image.data )
    {
      printf( "No image data n" );
      return -1;
    }
  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );
  waitKey(0);
  return 0;
}

生成项目时出错:

02:14:10 **** Rebuild of configuration Debug for project Ohm ****
Info: Internal Builder is used for build
g++ "-IC:\opencv\build\include" "-IC:\opencv\build\include\opencv" -O0 -g3 -Wall -c -fmessage-length=0 -o First.o "..\First.cpp" 
g++ "-LC:\opencv\build\x64\vc10\bin" -o Ohm.exe First.o -lopencv_core2410 -lopencv_ml2410 -lopencv_video2410 -lopencv_features2d2410 -lopencv_calib3d2410 -lopencv_objdetect2410 -lopencv_contrib2410 -lopencv_legacy2410 -lopencv_flann2410 -lopencv_core2410d -lopencv_highgui2410 -lopencv_highgui2410d -lopencv_imgproc2410 -lopencv_imgproc2410d 
First.o: In function `cv::Mat::~Mat()':
C:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
First.o: In function `cv::Mat::release()':
C:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
02:14:14 Build Finished (took 3s.794ms)

你不能将预构建的MSVC库(-LC:\opencv\build\x64\vc10\bin)与Mingw一起使用,它是一个不同的编译器。 获取 cmake,并使用它重建 OpenCV 库。(对不起,亲爱的,你没有其他办法。