Ask Your Question
1

Can't link to OpenCV DLL I compiled using Cmake

asked 2014-05-07 07:24:39 -0600

Y Simson gravatar image

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?

edit retag flag offensive close merge delete

Comments

I think using 3.0 is quite risky. It hasn't been released as stable, so I suggest using the 2.4 branch!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-08 03:57:44 -0600 )edit
1

Thanks. I am now working on compiling 2.4.9. It probably is safer.

Y Simson gravatar imageY Simson ( 2014-05-08 12:28:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-05-10 09:22:52 -0600

Y Simson gravatar image

Here is the solution to my problem

1) I forgot to add tbb.lib abd tbb_debug.lib to Properties ->Linker ->Input->Additional Dependencies

2) Cmake does not create include/opencv2/modules.... automatically. You have to do this yourself. Since this is very boring routine and tedious I wrote a script in python to do the job. Hopefully it will be useful for others.

3) In addition I went back to the stable version 2.4.9 which has just been released. I assume it safer than 3.0.0 which is still under development and has many new additions.

To summarize

0) Assuming you have downloaded the OpenCV Source files from github and have successfully compiled the code as follows: OpenCV249 - sources (the source code from github branch 2.4.9) - build (The destination directory you built into)

If you have trouble Compiling project using Cmake take look at this Installation Guide

For some reason the include directory is lacking the necessary *.h/hpp files you need to link to. For this purpose please copy this python script.

Place the script in the directory d:\OpenCV249 and run it

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

2) Add to path the following paths for the dlls:

%OPENCV64_DIR%\bin\Debug\;
%OPENCV64_DIR%\bin\Release\;

For compilation with TBB add this path as well:

%OPENCV64_DIR%common\tbb\bin\intel64\vc12\;

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 include these directories 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/;

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

For Debug: opencv_calib3d249d.lib;opencv_contrib249d.lib;opencv_core249d.lib;opencv_features2d249d.lib;opencv_flann249d.lib;opencv_haartraining_engined.lib;opencv_highgui249d.lib;opencv_imgproc249d.lib;opencv_legacy249d.lib;opencv_ml249d.lib;opencv_nonfree249d.lib;opencv_objdetect249d.lib;;opencv_photo249d.lib;opencv_shape249d.lib;opencv_softcascade249d.lib;opencv_stitching249d.lib;opencv_superres249d.lib;opencv_ts249d.lib;opencv_video249d.lib;opencv_videostab249d.lib;

For TBB add tbb_debug.lib;tbb.lib

For Release:

opencv_calib3d249.lib;opencv_contrib249.lib;opencv_core249.lib;opencv_features2d249.lib;opencv_flann249.lib;opencv_haartraining_engine.lib;opencv_highgui249.lib;opencv_imgproc249.lib;opencv_legacy249.lib;opencv_ml249.lib;opencv_nonfree249.lib;opencv_objdetect249.lib;opencv_photo249.lib;opencv_stitching249.lib;opencv_superres249.lib;opencv_ts249.lib;opencv_video249.lib;opencv_videostab249.lib;

For TBB add tbb.lib;

Note: There is a difference between the versions 3.0.0 and 2.4.9. If you are compiling the latest source instead of the source from branch 2.4.9 you will have in addition many additional libraries for cuda.

Also in version 3 ... (more)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-07 07:24:39 -0600

Seen: 7,544 times

Last updated: May 10 '14