0

I am following a tutorial about opencv, but when I build my project, a message of error is displayed:

#include <highgui.h>
#include <cv.h>

int main (int argc, char **argv) {

    cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);
    CvCapture* capture = cvCreateFileCapture("code.avi");
    IplImage *frame;
    
    while (1) {
        frame = cvQueryFrame(capture);
        if (!frame) break;
        cvShowImage("Example2",frame);
        char c = cvWaitKey(33);
        if (c == 27) break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("Example2");

    return 0;
}

The error message is this:

...undefined reference to cvCreateFileCapture
...undefined reference to cvQueryFrame
...undefined reference to cvReleaseCapture
Toshi
  • 63
  • 8
  • What OS are you compiling this on? The error suggests the library isn't being included or hasn't been installed – Scriptable Jan 09 '15 at 00:12
  • sorry, i forgot. Ubuntu 14.04. – Toshi Jan 09 '15 at 00:16
  • Ok, and hw is the project being built/compiled? Can you show your compile command? I'm not really familiar with opencv but your compile statement should include the library, like the example in this [other answer](http://stackoverflow.com/questions/6016815/how-to-include-needed-c-library-using-gcc) – Scriptable Jan 09 '15 at 00:23
  • I am building on eclipse. I imported all the libraries and include files. And the "Example1" worked just fine. – Toshi Jan 09 '15 at 00:40

1 Answers1

0

You have probably just forgotten to order the compiler to link the library which provides these functions. The name of the library that does might depend on the OpenCV version you are using. For OpenCV 3.0, try linking the lib videoio.

You can safely find out which library provides your function by using grep cvSomeFunction *.so in the folder where your OpenCV libraries have been installed to. To be even more sure, do nm someOpenCVLib.so | grep cvSomeFunction and check see the "T" output which tells you that the library provides this function:

00013570 T cvSomeFunction
Twonky
  • 774
  • 13
  • 29