OpenCV on ubuntu 11.10

I've just updated my system from ubuntu 11.04 to 11.10 and now I can't compile anymore any C program that contain references to OpenCV libraries

I've already tried to reinstall OpenCV (I use the 2.1 version) but I'm stuck with this error:

/tmp/ccArHTZL.o: In function `main':
z.c:(.text+0x59): undefined reference to `cvLoadImage'
z.c:(.text+0xa0): undefined reference to `cvNamedWindow'
z.c:(.text+0xb1): undefined reference to `cvShowImage'
z.c:(.text+0xbb): undefined reference to `cvWaitKey'
z.c:(.text+0xc5): undefined reference to `cvDestroyWindow'
z.c:(.text+0xd1): undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status

In order to install OpenCV I've always followed this procedure:

$ sudo apt-get install libcv2.1 libcv-dev libcvaux2.1 libcvaux-dev libhighgui2.1
     libhighgui-dev opencv-doc python-opencv

$ export LD_LIBRARY_PATH=/home/opencv/lib
$ export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

$ pkg-config --cflags opencv
     -I/usr/include/opencv

$ pkg-config --libs opencv
     -lcxcore -lcv -lhighgui -lcvaux -lml

$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.c

Anyone can help me?


Solution 1:

Why don't you use pkg-config to your favor?

g++ hello.c -o hello `pkg-config --cflags --libs opencv` 

Solution 2:

I think it is because of some changes from gcc 4.5 to gcc 4.6

Try this command instead (i.e., move the libraries to the end, instead of at the beginning of your command line) -- it works for me:

g++ -I/usr/include/opencv hello.c -lcxcore -lhighgui -lm