我在Windows上使用CMAKE从源代码构建OpenCV,我注意到编译的库具有版本扩展。所以,我有一些使用以下名称构建的库:opencv_dnn341.lib
其中341
,我想代表opencv版本3.4.1。
现在,当我尝试在另一个CMAKE项目中使用它时,我有这个找到opencv。类似的东西:
#cmake/opencv/CMakeLists.txt
FIND_PACKAGE(OpenCV REQUIRED)
SET(OpenCV_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS}
CACHE INTERNAL "OpenCV include dirs"
)
SET(OpenCV_LIBS ${OpenCV_LIBS}
CACHE INTERNAL "OpenCV libs"
)
现在,我尝试将CMAKE中的opencv库列为:
MESSAGE( STATUS "OPENCV_LIBS: ${OpenCV_LIBS}" )
这将库列为:
opencv_calib3d;opencv_core;opencv_dnn;...
请注意,文件名中缺少341
。结果,我的Visual Studio项目找不到这些库。为什么CMAKE没有生成正确的库名?
编辑
我的CMakeLists负责寻找OpenCV:
#cmake/opencv/CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0)
FIND_PACKAGE(OpenCV REQUIRED)
SET(OpenCV_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS}
CACHE INTERNAL "OpenCV include dirs"
)
SET(OpenCV_LIBS ${OpenCV_LIBS}
CACHE INTERNAL "OpenCV libs"
)
我在我的顶级CMakeLists中使用它:
PROJECT(RTFilter)
CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0)
SET(USE_OPENCV ON CACHE BOOL "ON OFF")
MARK_AS_ADVANCED(USE_OPENCV)
SET(HEADERS
nort.h
)
SET(SOURCES
main.cpp
)
if(USE_OPENCV)
ADD_SUBDIRECTORY(cmake/opencv)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
# TODO Need to infer the path of the OpenCV libs
LINK_DIRECTORIES(${OpenCV_DIR}/x64/vc15/lib)
message(STATUS, "LIBS: ${OpenCV_INCLUDE_DIRS}")
LIST(APPEND LIBS ${OpenCV_LIBS})
ADD_DEFINITIONS(-DUSE_OPENCV)
INCLUDE_DIRECTORIES(opencv)
LIST(APPEND HEADERS opencv/rtfilter.h)
LIST(APPEND SOURCES opencv/rtfilter.cpp)
endif(USE_OPENCV)
# Compile and link
ADD_LIBRARY(${NAME} SHARED ${HEADERS} ${SOURCES})
TARGET_LINK_LIBRARIES(${NAME} ${LIBS})