-1

My CMake project uses OpenCV, however, it links to the shared build, which requires the OpenCV DLLs for my executable to work. How can I tell CMake to use the static build of OpenCV instead?

What should I change in my CMakeList.txt file? This is how it looks right now:

cmake_minimum_required(VERSION 2.8)
project (Tutorial)
find_package (OpenCV REQUIRED)
add_executable (Tutorial WIN32 main.cpp)
target_link_libraries (Tutorial ${OpenCV_LIBS})
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

1

I found the answer, from https://stackoverflow.com/a/26920527/492336:

Actually this issue seems to have already been fixed in the OpenCVConfig.cmake that comes with OpenCV. All you have to do is define OpenCV_STATIC in your CMakeLists.txt. I.e.

set(OpenCV_STATIC ON)
find_package(OpenCV REQUIRED)

This worked for me, although I needed to specify the CRT to be static as well (because static OpenCV is linked against static CRT).

Community
  • 1
  • 1
sashoalm
  • 75,001
  • 122
  • 434
  • 781