1

I am using OpenCV 2.4.10 with eclipse C++ with MinGW. This version of opencv only has libraries for visual C so I linked those libraries in MinGW (eclipse). I tried running a simple code for loading and displaying an image:

#include<iostream>
#include<cv.h>
#include<highgui.h>
using namespace std;
using namespace cv;
int main(){
  Mat image = imread("D:/photo1.tif",1);
  namedWindow( "Display", WINDOW_AUTOSIZE );
  imshow( "Display", image );
return 0;
}

But while building it shows following errors:

undefined reference to `cv::imread(std::string const&, int)'
undefined reference to `cv::namedWindow(std::string const&, int)'
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'

I also tried the same with Tesseract OCR engine but there also it was showing the same problem i.e. undefined reference to various functions and classes. I don't know whether I am missing something in linking or building the files. So please help. Thanks

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Mogo
  • 11
  • 3
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Cory Kramer Dec 10 '14 at 13:20

4 Answers4

1

IMO Ashot's answer is almost correct, but I have a feeling you didn't build them at all. If that is the case..

Build for MinGW, the libraries have different links to all the code and you can't compile with different compiled libraries

GPPK
  • 6,546
  • 4
  • 32
  • 57
0

How did you build your code? If the compiler is GCC then you need to add opencv libs with -l flag.

You can find opencv libs with the command - pkg-config opencv --libs (in Linux).

Ashot Khachatryan
  • 2,156
  • 2
  • 14
  • 30
  • I am using G++ compiler and building the code in eclipse. Where can i find opencv mingw libraries in windows?? – Mogo Dec 11 '14 at 11:42
0

"This version of opencv only has libraries for visual C so I linked those libraries in MinGW (eclipse)."

no, this will not work.

you can't use the prebuild visual studio ones, those are for a different compiler.

you will have to get cmake and build the opencv libs with mingw first.

berak
  • 39,159
  • 9
  • 91
  • 89
0

Got it working by first buiding the libraries with CMake and then using it in eclipse.

Mogo
  • 11
  • 3