1

I am new to working with OpenCV. I am using Eclipse CDT and have installed MinGW. When ever I build the code, I get an error - Undefined reference to "cv::" in the object file i.e. .o created from .cpp code file.

Compiler Information: GCC C++ compiler, where I have included 3 folder paths:

  • "C:\OpenCV-3.0\opencv\build\include"
  • "C:\OpenCV-3.0\opencv\build\include\opencv"
  • "C:\OpenCV-3.0\opencv\build\include\opencv2"

Linker Information: MinGW C++ Linker:

  • Library serach path: "C:\OpenCV-3.0\opencv\build\x86\vc12\staticlib"
  • Libraries are added in this fashion:

    opencv_core2411d

    opencv_core2411


Code:

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp" using namespace cv;
#include <stdio.h>

int main( int argc, char** argv ) 
{
    Mat image;
    image = imread("D:/Work/April/Img_proc/image.jpg", 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;
}

Error :

**** Internal Builder is used for build ****
g++ -IC:\OpenCV-3.0\opencv\build\include -IC:\OpenCV-3.0\opencv\build\include\opencv2 -IC:\OpenCV-3.0\opencv\build\include\opencv -O0 -g3 -Wall -c -fmessage-length=0 -osrc\DisplayImage.o ..\src\DisplayImage.cpp
g++ -LC:\OpenCV-3.0\opencv\build\x86\vc12\staticlib -oOpenCV_CPP.exe src\DisplayImage.o -lopencv_core2411d -lopencv_core2411 -lopencv_imgproc2411d -lopencv_imgproc2411 -lopencv_highgui2411d -lopencv_highgui2411 -lopencv_ml2411 -lopencv_video2411 -lopencv_features2d2411 -lopencv_calib3d2411 -lopencv_objdetect2411 -lopencv_contrib2411 -lopencv_legacy2411 -lopencv_flann2411
src\DisplayImage.o: In function `main':
C:\Users\730716\workspace\OpenCV_CPP\Debug/../src/DisplayImage.cpp:14: undefined reference to `cv::imread(std::string const&, int)'
C:\Users\730716\workspace\OpenCV_CPP\Debug/../src/DisplayImage.cpp:20: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\Users\730716\workspace\OpenCV_CPP\Debug/../src/DisplayImage.cpp:21: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\730716\workspace\OpenCV_CPP\Debug/../src/DisplayImage.cpp:21: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\730716\workspace\OpenCV_CPP\Debug/../src/DisplayImage.cpp:22: undefined reference to `cv::waitKey(int)'
src\DisplayImage.o: In function `ZN2cv3MatD1Ev':
C:/OpenCV-3.0/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\DisplayImage.o: In function `ZN2cv3MataSERKS0_':
C:/OpenCV-3.0/opencv/build/include/opencv2/core/mat.hpp:298: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
src\DisplayImage.o: In function `ZN2cv3Mat7releaseEv':
C:/OpenCV-3.0/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
jenie
  • 21
  • 3
  • 1
    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) – Mateusz Grzejek May 04 '15 at 05:35
  • @Mateusz , The link you have shared is more of a generic solution. However, I need a point to point solution to the problem, which I do not find there. – jenie May 04 '15 at 05:42
  • 2
    you just cannot use the prebuild vs libs with mingw. if you insist on using mingw/eclipse , you will have to build the opencv libs **from src** using cmake – berak May 04 '15 at 05:43
  • @berak , okay, So what can be the possible workarounds ? I do not know that how to build opencv libs from src using cmake. Can you please help me with that, may be by providing some link with the process listed there.... – jenie May 04 '15 at 05:47

0 Answers0