Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can't link to OpenCV DLL I compiled using Cmake

Problem: I compiled OpenCVUsing Cmake and tried to create my own project by following the following Guide

This guide worked when linking to OpenCVs precompiled dll's I downloaded from OpenCV.org

However I prefer to compile my own Dlls and link to them.

Using this method, I compiled OpenCV from Source.

I did the following:

1) Define as a system variable OPENCV64_DIR = d:\opencv\build\ You should have in 'opencv' sub-folders named 'build' and 'sources'

2) Add to system Path the following paths for the dlls * %OPENCV64_DIR%\bin\Debug\; * %OPENCV64_DIR%\bin\Release\;

3) Open Visual Studio and create an empty console project

4) convert the project from 32 bit to 64 bit -Right click on solution -> Properties -> Configuration Properties -> Configuration Manager -> Platform -> New -> Choose x64 -> Click on OK to save changes

5) Add in project Properties ->C++ ->Additional Include Directories, the following directories: -$(OPENCV64_DIR)\include;

If you compiled OpenCV with TBB and Eigen directories include as well:
-$(OPENCV64_DIR)\common\tbb\include; -$(OPENCV64_DIR)\common\Eigen;

6) Add in project Properties ->Linker ->General ->Additional Library Directories:
-$(OPENCV64_DIR)\lib\$(Configuration);

Note: $(Configuration) stands for Release or Debug according the configuration mode chosen

If you compiled OpenCV with TBB include as well:
-$(OPENCV64_DIR)common/tbb/lib/intel64/vc12/; -$(OPENCV64_DIR)common/tbb/lib/intel64/vc12/$(Configuration);

7) Add in Properties ->Linker ->Input->Additional Dependencies, the following:

For Debug: opencv_calib3d300d.lib;opencv_contrib300d.lib;opencv_core300d.lib;opencv_cuda300d.lib;opencv_cudaarithm300d.lib;opencv_cudabgsegm300d.lib;opencv_cudacodec300d.lib;opencv_cudafeatures2d300d.lib;opencv_cudafilters300d.lib;opencv_cudaimgproc300d.lib;opencv_cudaoptflow300d.lib;opencv_cudastereo300d.lib;opencv_cudawarping300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_haartraining_engined.lib;opencv_highgui300d.lib;opencv_imgproc300d.lib;opencv_legacy300d.lib;opencv_ml300d.lib;opencv_nonfree300d.lib;opencv_objdetect300d.lib;opencv_optim300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_softcascade300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videostab300d.lib;

For Release: opencv_calib3d300.lib;opencv_contrib300.lib;opencv_core300.lib;opencv_cuda300.lib;opencv_cudaarithm300.lib;opencv_cudabgsegm300.lib;opencv_cudacodec300.lib;opencv_cudafeatures2d300.lib;opencv_cudafilters300.lib;opencv_cudaimgproc300.lib;opencv_cudaoptflow300.lib;opencv_cudastereo300.lib;opencv_cudawarping300.lib;opencv_features2d300.lib;opencv_flann300.lib;opencv_haartraining_engined.lib;opencv_highgui300.lib;opencv_imgproc300.lib;opencv_legacy300.lib;opencv_ml300.lib;opencv_nonfree300.lib;opencv_objdetect300.lib;opencv_optim300.lib;opencv_photo300.lib;opencv_shape300.lib;opencv_softcascade300.lib;opencv_stitching300.lib;opencv_superres300.lib;opencv_ts300.lib;opencv_video300.lib;opencv_videostab300.lib;

After doing all of this, I get the following Error:

main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release@Mat@cv@@QEAAXXZ)

From the following code:

#include <iostream>
#include <stdio.h>
#include "opencv2\opencv.hpp"
using namespace std;
using namespace cv;
/** @function main */
int main(int argc, const char** argv)
{
    cout << "Hello world x64" << endl;

Mat image;
String inputName;

return 0;
}

What does work, is compiling the code by actually adding the opencv projects to my solution like in OpenCV's examples. See EXAMPLE cout_mat

This is time consuming and compiles the modules every time I compile my project.

Any better ideas? What am I missing?