1

I've installed OpenCV via this instruction.

I use OpenCV when and build the code via cmake - and it's all ok. But now I'm trying to use OpenCV from QT, and I get errors like this:

 error: undefined reference to `cvCreateCameraCapture'

The same errors for all functions from OpenCV.

I tried to add in .pro this code:

INCLUDEPATH += /usr/local/include/opencv2
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann

But it isn't work. The dir /usr/local/include/opencv2 exist and not empty.

So, what's wrong?

Andrew
  • 399
  • 5
  • 17

2 Answers2

2

Add this to .pro file:

LIBS += "pkg-config --libs opencv"         
Andrew
  • 399
  • 5
  • 17
kiranpradeep
  • 10,859
  • 4
  • 50
  • 82
  • dear Downvoter, the answer has been thanked by OP. please read OP's comments in question before further down voting or leave a comment for the reason for down voting. – kiranpradeep Apr 02 '15 at 02:34
  • Look here as well: http://stackoverflow.com/questions/16972066/using-pkg-config-with-qt-creator-qmake-on-mac-osx – Alexander V Dec 06 '16 at 23:49
0

You are getting a linker error, so the compilation is correct. In order to add correctly the linking library directories and the linking libraries to your .pro file you should issue a command like this at the console:

username@linux-host:~> echo $(pkg-config --libs opencv)

You should then read a long list of libraries as in the following line:

-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab /usr/lib64/libXext.so /usr/lib64/libX11.so /usr/lib64/libICE.so /usr/lib64/libSM.so /usr/lib64/libGL.so /usr/lib64/libGLU.so -lrt -lpthread -lm -ldl

After you have obtained this long sequence of strings with all the libraries and the options, insert it in the .pro file like this:

LIBS += -lopencv_calib3d -l... ...insert all the strings as seen above!

Save the .pro file, re-run qmake and run make again. The linking error should have disappeared.

If the problem is not disappeared or if other linking errors are shown, find all the files with the extension .pc in your opencv compilation directory (and subdirectories) and copy them as root in the directory /usr/share/pkgconfig/

Then issue again the command above and insert in the .pro file the correct sequence of strings that identify the library options in the LIBS += line and save the .pro file, re-run qmake and re-run make.