更新时间:2023-11-16 16:09:16
您应使用 CMAKE_CURRENT_SOURCE_DIR
指定此目录.您还应该在此处添加 $ {OpenCV_INCLUDE_DIRS}
,如在CMake中使用OpenCV"
You should use target_include_directories()
to tell CMake to associate specific include directories containing your headers with the DisplayImage
target. Assuming your Camera.h
file is in the same directory as Camera.cpp
, you can use CMAKE_CURRENT_SOURCE_DIR
to specify this directory. You should also add the ${OpenCV_INCLUDE_DIRS}
here, as shown in the "Using OpenCV with CMake" tutorial.
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp Camera.cpp )
target_include_directories(DisplayImage PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries( DisplayImage PRIVATE ${OpenCV_LIBS} )
注意:总是 指定作用域参数(例如 PUBLIC
, PRIVATE
或 INTERFACE 代码>)中的
target _ *
命令.
Note: it is good CMake practice to always specify the scoping argument (e.g. PUBLIC
, PRIVATE
, or INTERFACE
) in the target_*
commands.