Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the OpenCV 2.4 static libraries with Visual Studio?

I'm trying to set up OpenCV 2.4 as follows:

  • I've downloaded and extracted the precompiled package to C:\OpenCV240.
  • In Visual Studio, I've added C:\OpenCV240\build\include as an additional include directory.
  • Furthermore, I've added C:\OpenCV240\build\x86\vc10\staticlib as an additional library directory.
  • And I've specified all available .lib files as additional dependencies.

When I compile my "Hello World" program (which compiles just fine when using the DLLs), I get a lot error messages like this:

1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in opencv_core240d.lib(matrix.obj)

What am I doing wrong?

like image 788
Niko Avatar asked May 13 '12 09:05

Niko


1 Answers

It sounds like you need to specify linking against the static C runtime library in your program.

If OpenCV linked against the static CRT and you use the dynamic one, you get these types of redefinition errors.

To change this setting, open your project's Properties and go to Configuration Properties -> C/C++ -> Code Generation.

Change Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaded Debug (/MTd). Do the same for your other configurations, using the non-Debug variant where appropriate.

like image 154
Fraser Avatar answered Nov 16 '22 12:11

Fraser