OpenCV on ubuntu 11.10

I just upgraded my system from ubuntu 11.04 to 11.10, and now I can no longer compile any C program containing links to OpenCV libraries.

I have already tried reinstalling OpenCV (I am using version 2.1 ), but I am 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

To install OpenCV, I always performed 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

Can anybody help me?

+3
source share
5 answers

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

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

I think this is due to some changes from gcc 4.5 to gcc 4.6

Try using this command (i.e. move the libraries to the end, and not at the beginning of the command line) - this works for me:

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

+2

kubuntu 10.10, , 11.10, ldconfig sudo. . , /usr/lib, /usr/lib64 /usr/lib32, apt-get . , LD_LIBRARY_PATH, . , /home/opencv/lib , ,

0

I just updated to 11.04 on my laptop and had similar problems. I would try to create the latest version of OpenCV (2.3.1) and see if this fixes something, this seems to fix several issues for me.

0
source

Use the following command, this worked for me:

gcc pkg-config --cflags opencvopencv.c -o open_cvpkg-config --libs opencv

0
source

All Articles