Reputation: 707
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
Upvotes: 2
Views: 1792
Reputation: 91
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`
Upvotes: 4
Reputation: 263
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)
.
Upvotes: 0