user1446316
user1446316

Reputation: 69

opencv linking error after mixing c++ with c version

I'm working with opencv 2.4.0 using eclipse CDT (Indigo Service Release 2) on windows 7 64 bit machine. I complied opencv from sources (using cmake/visual studio express 10) following the steps described on the opencv download site.

Everything worked well when I was using opencv C functions (in my C++ code). When I tried to use cv::Mat, it gave me a linking error (like: undefined reference to `cv::Mat::Mat(_IplImage const*, bool)').

Upvotes: 0

Views: 647

Answers (2)

user1446316
user1446316

Reputation: 69

found a solution. when using eclipse with mingw tool chain you should compile opencv with mingw as well. compiling opencv from command line worked for me.

  1. follow section 'Compile using GCC from command line' from the opencv InstallGuide
  2. in addition to mingw32-make, make -j, also do a 'make install'. this will create an install directory in the folder where you build your opencv binaries. the opencv libraries will be placed be install/lib
  3. the lib files in install/lib will have a '.dll.a' extension like 'libopencv_core243.dll.a'. to link to these lib files in your project go to Properties->C/C++ General->Paths and Symbols->Libraries. then add the library name without the prefix 'lib' and suffix '.dll.a'. so to link to 'libopencv_core243.dll.a' just use 'opencv_core243'

Upvotes: 0

rotating_image
rotating_image

Reputation: 3076

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;

int main()
{
    IplImage *image = cvLoadImage("C:\\any_picture.jpg");
    Mat m = Mat(image);
    imshow("test",m);
    waitKey();
    return 0;
}
  1. try the above code by linking the debug files like opencv_core240d.lib,opencv_highgui240d.lib,opencv_imgproc240d.lib
  2. add the path to the bin folder to the environment variable
  3. try to get the latest opencv i.e. 2.4.3

Upvotes: 1

Related Questions