c++opencvvisual-studio-2013

Linking error when I include dnn module in opencv 3.1.0


I tried to use dnn module of Opencv 3.1.0 to do some object detection, which I follow tutorial here: Opencv dnn module tutorial

From my understanding, extra module, which contain dnn module, should be built with Opencv source. So I follow this tutorial: Build Opencv with Extra Modules.

However, when I try to compile this simple code in Microsoft Visual Studio 2013,

#include <opencv2\dnn.hpp>
#include <opencv2\core.hpp>
using namespace cv;
using namespace cv::dnn;

void main() {

}

1>------ Rebuild All started: Project: WithDnnModule, Configuration: Debug Win32 ------ 1> DnnTest.cpp 1>DnnTest.obj : error LNK2019: unresolved external symbol "private: void __thiscall cv::String::deallocate(void)" (?deallocate@String@cv@@AAEXXZ) referenced in function "public: __thiscall cv::String::~String(void)" (??1String@cv@@QAE@XZ) 1>C:\Rescourse\Project\opencvdnn\WithDnnModule\Debug\WithDnnModule.exe : fatal error LNK1120: 1 unresolved externals ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

If I don't include opencv2\dnn.hpp, I can build the code successfully.

Please help me out.


Solution

  • I had a very similar problem. It turned out that I was trying to link against the x64 opencv lib/dll but my project was set to x86.