13 December 2012

Static Linking OpenCV in Visual Studio 2010

A static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker or binder, producing an object file and a stand-alone executable. When you link OpenCV libraries statically, it produces a single large executable or binary which doesn't require any opencv dlls to run. The precompiled opencv binary comes with dynamic library as well as static library in the build folder. opencv\build\x86\vc10\staticlib contains the static library files and opencv\build\x86\vc10\lib contains dynamic library files.

Take the following steps to statically link OpenCV to your Visual Studio project -
Step 1: Go to your Project->Properties. Add the OpenCV include directory to your project's additional include directories.
Step 2: Now go the Linker->General Settings-> Additional Library Directories and add the OpenCV static library location.
Step 3: Go to the Linker->Input->Additional Dependencies and add the OpenCV static libraries here. Apart from the basic opencv libraries like opencv_core243.lib, opencv_highgui243.lib that you need, you need to add the libtiff.lib, libpng.lib, libjpeg.lib, libjasper.lib, IlmImf.lib, zlib.lib. These library files are required by other opencv libraries. Try to compile your project. If it doesn't compile, add Vfw32.Lib and comctl32.lib to the library list. These libraries are visual studio libraries which are also required.

Try to compile your project now, it should work.