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.


  1. I also had to use Linker->Ignore Specific Default Libraries = libcmt.lib;msvcprt.lib to get it to link.

    1. Thanks for additional information. Though it worked for me without Ignoring those specific libraries.

  2. I'm getting the error "LINK : fatal error LNK1181: cannot open input file 'llmlmf.lib'"
    What do you think I'm doing wrong?

    1. llmlmf.lib is OpenEXR lib used to handle openexr images. OpenCV requires this library if you have enabled this option during cmake. Try checking your cmake flags. If you have built opencv without openexr, then you don't need to link llmlmf.lib.