0

I am trying to compile a simple program using OpenCV in Ubuntu Quantal. I have installed all the OpenCV packages available. My code is the following

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

int main(int argc, char *argv[]) {
        IplImage* img=0; /* pointer to an image */
        printf("Hello\n");
        if(argv[1] != 0)
                img = cvLoadImage(argv[1], 0); // 1 for color
        else
                printf("Enter filename\n");
        if(img != 0) {
                cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
                cvShowImage("Display", img); // show image in window
                cvWaitKey(0); // wait until user hits a key
                cvDestroyWindow("Display");
        }
        else
                printf("File not found\n");
        return 0;
}

And my compile command is g++ -I/usr/include/opencv -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann main.cpp -o main

And I get the following errors

/tmp/ccUQ4Tm4.o: In function `main':
main.cpp:(.text+0x45): undefined reference to `cvLoadImage'
main.cpp:(.text+0x6b): undefined reference to `cvNamedWindow'
main.cpp:(.text+0x7c): undefined reference to `cvShowImage'
main.cpp:(.text+0x86): undefined reference to `cvWaitKey'
main.cpp:(.text+0x90): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status
make: *** [all] Error 1

What I understand from the errors above is that there is no problem finding the library but the compiler cannot find the functions inside it. Can you please help me out with that?

1 Answer 1

3

include all of your libraries in the last.

e.g.

g++ -I/usr/include/opencv main.cpp -o main -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann  

It resolves symbols as it find libraries in the same sequence as it is written on commandline.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .