1
votes

I have installed opencv it compiled 100%, i have run a command: pkg-config --cflags --libs opencv It's output is:-I/usr/include/opencv -I/usr/include/opencv4 -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui

But when i try to compile a c++ code it gives cannot find error, I don't know what to do. Thanks..

~/cpp_test$

g++ main.cpp -o output `pkg-config --cflags --libs opencv`
/usr/bin/x86_64-linux-gnu-ld: cannot find -lopencv_contrib
/usr/bin/x86_64-linux-gnu-ld: cannot find -lopencv_legacy
collect2: error: ld returned 1 exit status
2
Check if the opencv_contrib.so and opencv_legacy.so are in the /usr/lib folder, if not, create symlinks to the actual library files in /usr/libSoulimane Mammar

2 Answers

2
votes

If you installed OpenCV 4, I'm pretty confident that you met the same problem as mine.

The solution is actually pretty simple, you just need to run

g++ main.cpp -o output `pkg-config --cflags --libs opencv4`

instead of

g++ main.cpp -o output `pkg-config --cflags --libs opencv`
0
votes

after installation of Opencv, symbolic linking has to be done to make a link for the library to a known lib location. Try the command on terminal sudo ldconfig, to dynamically link the library.

And then compile g++ main.cpp -o output $(pkg-config --cflags --libs opencv).