0

I have same problem like:

How to link opencv and other dll files to output exe of visual studio 2013

the answer say:

There you change the extension of all the openCV libraries from .dll to .lib

i download the .lib in https://opencv.org/releases/, which have .lib in opencv\build\x64\vc15\lib

follow is my CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
set(prjName opencv_demo)
project(${prjName})

set(CMAKE_CXX_STANDARD 14)

# this is static libraries, have *.lib
set(OpenCV_DIR "C:\\opencv\\build\\x64\\vc15\\lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
find_package(OpenCV REQUIRED)

add_executable(opencv_demo main.cpp)
target_link_libraries(${prjName} PUBLIC ${OpenCV_LIBS})

but it still need dll.

i search that may cmake mt like

set_property(TARGET ${prjName} PROPERTY
  MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

but it still need dll.

what should i do?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Para
  • 1,299
  • 4
  • 11
  • You don't link native dlls with msvc. Instead you link the import `.lib` file that goes with the dll. – drescherjm Nov 23 '22 at 05:35
  • Using the download is not following the procedure in the thread you quoted. "First you need to rebuild openCV to generate static libraries instead of dynamically linked ones." – drescherjm Nov 23 '22 at 05:38
  • 1
    This question should help you determine if the `.lib` files you have are import libraries (requiring a dll at runtime) or static libraries: [https://stackoverflow.com/questions/8019464/static-library-v-s-import-library-on-windows-platform](https://stackoverflow.com/questions/8019464/static-library-v-s-import-library-on-windows-platform) – drescherjm Nov 23 '22 at 05:42
  • @drescherjm, tks!!! now i know that .lib files are a import libraries, not a static libraries. – Para Nov 23 '22 at 07:39
  • 1
    that other answer you found... **no**, you *can't* just *rename* `.dll` files to `.lib`. that doesn't work. – Christoph Rackwitz Nov 23 '22 at 12:26
  • ***what should i do?*** I recommend a different approach. Take the same approach almost every commercial application does and build an installer for your application. In many cases building an installer is the easier approach and in some cases dlls will be a requirement regardless. At work since I switched to CMake in 2008 I have CMake generate me an installer using NSIS. – drescherjm Nov 23 '22 at 16:49

0 Answers0