在包含中找不到 CMake 头文件

CMake header files not being found in include

本文关键字:文件 CMake 找不到 包含中      更新时间:2023-10-16

我有库,AprilTags,它使用cmake top build它。

我还有另一个项目AIV,它使用AprilTags。我想将 apriltags 库保留在 ~/aiv/apriltags 中,但有另一个文件,front_back_camera_demo它使用 AprilTags 库中的一些文件。

所以文件结构看起来像

~/aiv/build/
/apriltags/CMakeLists.txt
/apriltags/AprilTags/TagDetector.h
/apriltags/AprilTags/*.h
/front_back_camera_demo.cpp
/CMakeLists.txt

当我在顶级CMakeLists.txt上运行cmake时,它成功地构建了AprilTags库,但随后我得到了一个

front_back_camera_demo.cpp:72:35:致命错误:AprilTags/TagDetector.h:没有这样的文件或目录

错误在我包含 AprilTags/TagDetector.h 的行上

以下是两个相关的CMakeList.txt:

顶级:

cmake_minimum_required(VERSION 2.6)
project(AIV)
add_subdirectory(apriltags)
add_executable(front_back_camera_demo front_back_camera_demo.cpp 
Serial.cpp)
target_link_libraries(front_back_camera_demo apriltags)

四月内标签:

cmake_minimum_required(VERSION 2.6)
project(apriltags)
#add_definitions(-pg) #"-fopenmp)
# pull in the pods macros. See cmake/pods.cmake for documentation
set(POD_NAME apriltags)
include(cmake/pods.cmake)
file(GLOB SOURCE_FILES "src/*.cc")
include_directories(AprilTags . /opt/local/include)
add_library(apriltags ${SOURCE_FILES})
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(apriltags ${OpenCV_LIBS}) #-pg) #-fopenmp)
pods_use_pkg_config_packages(apriltags eigen3)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(apriltags -L/opt/local/lib/) # MacPorts 
special treatment...
else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
pods_use_pkg_config_packages(apriltags libv4l2)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
pods_install_libraries(apriltags)
file(GLOB header_files "AprilTags/*.h")
pods_install_headers(${header_files} DESTINATION AprilTags/)
pods_install_pkg_config_file(apriltags
LIBS -lapriltags
REQUIRES eigen3 opencv2
VERSION 1.0.0)
add_subdirectory(example)

我做错了什么?

首选target_*命令。

apriltags/CMakeLists.txt:

target_include_directories(apriltags
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/AprilTags"
/opt/local/include)

也就是说,所有使用apriltags目标的人都将能够访问"."中的任何包含,apriltags也可以使用 ".",并且只有apriltags本身使用"AprilTags"和"/opt/local/include"目录下的内容。

如果你真的知道自己在做什么,你可以通过使用生成器表达式来获得更细粒度的表达式,但这不是让它工作所必需的。