C++ guide

OpenCV C++ on Windows — Visual Studio setup guide

Configure OpenCV 4.12.0 for C++ in Visual Studio on Windows 10 and 11. Covers include directories, linker settings, PATH for DLLs, and fixing common build errors.

This guide covers configuring OpenCV from the official pre-built Windows binary. For a CUDA build see CUDA / GPU guide.

Download the official OpenCV Windows binary

Download opencv-4.12.0-windows.exe from the download page or from github.com/opencv/opencv/releases. Run the self-extracting archive and extract to C:\opencv.

After extraction, the key folders are:
C:\opencv\build\include\ # header files
C:\opencv\build\x64\vc16\lib\ # .lib files for linking
C:\opencv\build\x64\vc16\bin\ # .dll files — add to PATH

Add OpenCV bin to Windows PATH

Before configuring Visual Studio, add the OpenCV bin directory to your system PATH so Windows can find the DLLs at runtime:

  • 1

    Open Environment Variables

    Win+S → search Edit the system environment variables → click Environment Variables.

  • 2

    Edit System Path

    Under System variables, click PathEditNew.

  • 3

    Add the bin path

    Path to add
    C:\opencv\build\x64\vc16\bin

    Click OK on all dialogs. Restart Visual Studio for the change to take effect.

Configure Visual Studio project

For each Visual Studio project that uses OpenCV, set these three properties. Right-click your project → Properties.

Property pageSettingValue
C/C++ → GeneralAdditional Include DirectoriesC:\opencv\build\include
Linker → GeneralAdditional Library DirectoriesC:\opencv\build\x64\vc16\lib
Linker → InputAdditional Dependenciesopencv_world4120.lib (Release) or opencv_world4120d.lib (Debug)
Make sure your project platform is set to x64, not Win32. OpenCV pre-built binaries are 64-bit only.

Verify the setup with a minimal test

main.cpp
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
std::cout << "OpenCV: " << CV_VERSION << std::endl;
return 0;
}
// Expected output:
OpenCV: 4.12.0

C++ setup questions

opencv_world4120.dll was not found
The DLL directory is not on PATH. Add C:\opencv\build\x64\vc16\bin to your system PATH and restart Visual Studio and your terminal. See opencv_world.dll fix guide.
LNK1107: invalid or corrupt file: cannot read
You are linking against the wrong .lib file. For Release builds use opencv_world4120.lib. For Debug builds use opencv_world4120d.lib. Make sure your project configuration (Release/Debug) matches the lib file.
Which vc version to use (vc14, vc15, vc16)?
Use the version matching your Visual Studio: vc14 = VS 2015, vc15 = VS 2017, vc16 = VS 2019/2022. OpenCV 4.12.0 ships with vc16 which works for both VS 2019 and VS 2022.
Can I use CMake instead of Visual Studio project properties?
Yes — see the CMake guide. CMake is recommended for projects that need to be portable or cross-platform, or when building multiple executables from one configuration.

DLL not found errors?

Full fix guide for opencv_world.dll and PATH issues.

opencv_world.dll fix