2
votes

I try to integrate the OpenCV library into my Qt-based project in Visual Studio 2012. I know there exist a lot of other threads to this problem but none solved my linking issues. Here is my setup:

  • Windiws 8.1 64-Bit
  • Visual Studio 2012 32-Bit
  • OpenCV 3.0
  • Qt 5.1 32-Bit and Qt Add-In 1.2.3

I downloaded the OpenCV 3.0 Windows package and used CMake and the Visual Studio compiler to build it; I followed this instruction. The build folders look like this: . The .lib and .dll files were generated correctly: enter image description here Then I followed the instruction on the official OpenCV page and this one and did the following configurations:

  • VC++ Directories ‣ "Executable Directories": I added the path to the bin folder which is shown in the third picture
  • VC++ Directories ‣ "Library Directories": I added the path to the lib folder shown in the second picture
  • C/C++ ‣ General ‣ "Additional Include Directories": here I added the path to the original include folder of the extracted OpenCV package as the build includes folder is empty
  • Linker ‣ General ‣ "Additional Library Directories": here I added the path to the lib files
  • Linker ‣ Input ‣ "Additional Dependencies": here I listed all libraries like this:
    opencv_core300d.lib
    opencv_highgui300d.lib
    opencv_imgproc300d.lib
    opencv_video300d.lib
    opencv_calib3d300d.lib
    opencv_contrib300d.lib
    opencv_features2d300dd.lib
    opencv_flann300d.lib
    opencv_gpu249d.lib
    opencv_legacy300d.lib
    opencv_ml300d.lib
    opencv_nonfree300d.lib
    opencv_objdetect300dd.lib
    opencv_ocl300d.lib
    opencv_photo249d.lib
    opencv_stitching300d.lib
    opencv_superres300d.lib
    opencv_ts300d.lib
    opencv_videostab300d.lib

I also want to note that I can not change the code generation to /MTd as Qt would not work with that (but that should not be the problem since I build OpenCV activating the option WITH_QT in the CMake configuration)

Additionally I put all .dll files in the same directory as my generated debug .exe (Visual Studio otherwise complained that the .dll could not be found)

When I try to execute a function of the OpenCV lib or only create an object I always get unsolved link errors like this one:

Fehler 2 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread@cv@@YA?AVMat@1@ABVString@1@H@Z)" in Funktion "_main".

or this one

Fehler 2 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall cv::VideoCapture::VideoCapture(void)" (??0VideoCapture@cv@@QAE@XZ)" in Funktion ""void __cdecl loadMovie(class QString)" (?loadMovie@@YAXVQString@@@Z)".

I really would appreciate the help since I have been struggling for one whole week now trying everything I found on the internet.

1
can you add the other libs too? e.g. opencv_videoio300d.lib ... since opencv3 there are some functionalities split from highgui to different libs. not sure where imread is placed now.Micka
probably opencv_imgcodecs300d.libMicka
thank you for your quick response; I added opencv_imgproc300d.lib and opencv_imgcodecs300d.lib to the linker input and the link seems to be resolved.I try to include the other libraries not listed by the OpenCV documentation and try to get the VideoCapture working. Hoepfully that will work; again I apperciate your quick answer.vein
very well written question btw, which makes quick answering possible without asking for additional information =)Micka

1 Answers

1
votes

The problem is, that the provided link How to build applications with OpenCV inside the Microsoft Visual Studio is for OpenCV 2.4.11 where libraries were managed a little bit different.

From OpenCV 3.0 on, opencv_highgui lib is split to different sub-libraries concerning VideoCapture, image reading and other stuff. As you can see in your screenshot, there are other libs, which you didn't add yet to your project, e.g. opencv_imgcodecs300d.lib and opencv_videoio300d.lib

Try to add all those libraries. If that works, and if you want to reduce dependencies, you can remove libraries until linker fails.