openCV error : undefined reference to `cvLoadImage' Ubuntu
21,357
You used single quotes '
instead of backquotes/backticks `
. This is the corrected command:
g++ hello.cpp -o hello `pkg-config --cflags --libs opencv`
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I have installed the openCV libraries but I am still getting the error
$ g++ -I /usr/include/opencv/ -L -lcxcore -lhighgui hello.cpp -o hello
/tmp/ccjjrbXr.o: In functionmain': hello.cpp:(.text+0x2d): undefined reference to
cvLoadImage'
collect2: ld returned 1 exit statusWhen I check for the path of the libraries I get
$ pkg-config --libs opencv
-lml -lcvaux -lhighgui -lcv -lcxcoreI have written a very simple program to test it :
enter code here #include< cv.h> #include< highgui.h> /* required to use OpenCV's highgui */ #include< stdio.h> int main() { IplImage* img = 0; printf("Hello\n"); img = cvLoadImage("lena.jpg", 0 ); }
There is something wrong with my installation but I am really not able to figure it out. Any guidance will be highly appreciated! Thanks
When I run:
$ pkg-config --cflags --libs opencv -I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
But when I run:
$ g++ 'pkg-config --cflags --libs opencv' display_image.cpp g++: error: pkg-config --cflags --libs opencv: No such file or directory
OpenCV seems to be installed but still the problem persists.
-
Admin about 12 yearsSorry, I actually had entered linked all the libs, but made a mistake while entering it the forum. It still gives the same error: '** g++ -I /usr/include/opencv/ -L -lhighgui hello.cpp -o hello /tmp/ccw90mKu.o: In function
main': hello.cpp:(.text+0x2d): undefined reference to
cvLoadImage' collect2: ld returned 1 exit status '** -
Martin Beckett about 12 years@user1111044 - then it probably can't find the lib. Don't you have to specify a directory if you use "-L" ? this might be blocking the standard LD_LIBRARY_PATH search
-
Admin about 12 yearsYeah that's the exact problem that I am facing. I do not have a folder to use along with the -L.
-
Martin Beckett about 12 yearsIt's probably
/usr/local/lib
but see opencv.willowgarage.com/wiki/InstallGuide_Linux -
Admin about 12 yearsnah..have tried all these. But thanks a lot Martin for trying to help!