'unresolved external symbol' error when linking with OpenCV 3.0

Solution 1:

Here the steps to use OpenCV 3.0.0 with precompiled libs, for a C++ project that links OpenCV statically, in Windows (tested with Windows 8.1) and Visual Studio (tested with Visual Studio 2013) to run this program:

#include <opencv2\opencv.hpp>
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");
    imshow("img", img);
    waitKey();
    return 0;
}
  1. Download from http://opencv.org/downloads.html
  2. Extract
  3. Let's call OPENCV_DIR the dir containing:
    • build
    • source
  4. Create an empty project:
    • New Project -> Visual C++ -> Empty Project
  5. Add a cpp file (say Start.cpp) that will contain your main function (e.g. the snippet above)
  6. Configuration DEBUG
  7. Add include and lib directories:
    • Configuration Properties -> VC++ Directories
    • Include Directories: add OPENCV_DIR\build\include
    • Library Directories: add OPENCV_DIR\build\x86\vc12\staticlib
  8. Add required libs (the following are good for this simple example, you should add more if you need other functionalities):

    • opencv_core300d.lib
    • opencv_highgui300d.lib
    • opencv_imgproc300d.lib
    • opencv_hal300d.lib
    • opencv_imgcodecs300d.lib
    • libjpegd.lib;
    • libpngd.lib
    • libjasperd.lib
    • IlmImfd.lib
    • libtiffd.lib
    • libwebpd.lib
    • zlibd.lib
    • ippicvmt.lib
    • %(AdditionalDependencies)
  9. Configuration Properties -> C/C++ -> Code Generation -> Runtime Library

    • Set to Multi-threaded Debug (/MTd)
  10. For a RELEASE build, you need to do steps from 6 to 9 in release mode, adding libs without the trailing "d" in step 8, and Multi threaded (/MT) in step 9.

  11. Enjoy!

As a bonus, I also recommend to install Image Watch extension for Visual Studio. Very very useful for debugging your Mats!