OpenCV error: undefined link to `cvLoadImage 'Ubuntu

I installed openCV libraries, but I still get the error
$ g ++ -I / usr / include / opencv / -L -lcxcore -lhighgui hello.cpp -o hello
/tmp/ccjjrbXr.o: In the main': hello.cpp:(.text+0x2d): undefined reference to function main': hello.cpp:(.text+0x2d): undefined reference to cvLoadImage "
collect2: ld returned 1 exit status

When I check the library path, I get $ pkg-config --libs opencv
-lml -lcvaux -lhighgui -lcv -lcxcore

I wrote a very simple program for testing:

 enter code here #include< cv.h> #include< highgui.h> /* required to use OpenCV highgui */ #include< stdio.h> int main() { IplImage* img = 0; printf("Hello\n"); img = cvLoadImage("lena.jpg", 0 ); } 

Something is wrong with my installation, but I'm really not able to figure it out. Any guidance would be greatly 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 the problem still persists.

+6
source share
4 answers

You used single quotes ' instead of backquotes / backticks ` . This is the corrected command:

 g++ hello.cpp -o hello `pkg-config --cflags --libs opencv` 
+11
source

It would be nice to contact highgui lib -lhighgui if you use it

0
source

this command:

 g++ 'pkg-config --cflags --libs opencv' display_image.cpp 

different from this:

 g++ `pkg-config --cflags --libs opencv` display_image.cpp 

due to the `and 'characters ...

If you do not want to mess with these characters, you can use

 g++ $(pkg-config --cflags --libs opencv) display_image.cpp 

which is easier to visualize

0
source

try g ++ -g -o mypro progname.cpp pkg-config opencv --cflags --libs or

-1
source

Source: https://habr.com/ru/post/912877/


All Articles