opencv compile errors with g++

hi,
I am trying to compile the hello world opencv program,

g++ hello.c -o hello

And I am getting the following errors:

/tmp/cca4w5Eo.o: In function `main':
hello.c:(.text+0x23): undefined reference to `cvLoadImage'
hello.c:(.text+0x36): undefined reference to `cvNamedWindow'
hello.c:(.text+0x47): undefined reference to `cvShowImage'
hello.c:(.text+0x51): undefined reference to `cvWaitKey'
hello.c:(.text+0x5d): undefined reference to `cvReleaseImage'
hello.c:(.text+0x67): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status



1
2
3
4
5
6
7
8
9
10
11
#include "/usr/include/opencv/highgui.h"

int main( int argc, char** argv ) 
{
    IplImage* img = cvLoadImage( argv[1] );
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Example1", img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Example1" );
}


Does anyone know what I could be doing wrong?
You need to link to the library.
(You should also omit /usr/include in the header include)
Thanks Bazzy,.

I've tried :

1
2
3
g++ hello.c -lopencv -o hello
g++ hello.c -lopencv.x86_64 -o hello
g++ hello.c -lopencv-devel.x86_64 -o hello


The opencv book doesn't go into detail about compiling so I'm not exactly sure how to link the library
Look into the -l, -I, and -L options of g++; -l specifies the library to link with, -I specifies the path to include header files, and -L specifies the library path. You might be looking for the LD_LIBRARY_PATH environment variable after you get it compiled.

Use man gcc for more information.
Last edited on
I finally found this:
http://opencv.willowgarage.com/wiki/CompileOpenCVUsingLinux

this should get me started

Thanks
Topic archived. No new replies allowed.