在包含中找不到 CMake 头文件
CMake header files not being found in include
我有库,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"目录下的内容。
如果你真的知道自己在做什么,你可以通过使用生成器表达式来获得更细粒度的表达式,但这不是让它工作所必需的。
相关文章:
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 现代CMake(3.8+)-FindCUDA已弃用,非.cu文件呢
- 如何通过Conan和CMake找到用于pkg配置的.pc文件
- MinGw 无法从 cmake 编译测试文件
- cmake:添加要搜索头文件的目录
- 库标题在标题中不可见,但在 cmake build 下.cpp文件中完全可见.为什么?
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 使用 Makefile 中的头文件编译 Pybind (不使用 cmake)
- CMake:在其他目录中找不到我的头文件
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 无法使用 CMake 从其他文件夹添加源文件
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- 使用 Cmake 在 Qt Creator 中显示头文件
- CMake 生成的 MSVC 项目找不到符号,即使为其相关 dll 正确生成了 lib 文件也是如此
- 告诉CMake链接到自定义文件夹中的Boost
- Vcpkg Pango CMake 构建失败缺少头文件
- 从不同的文件cmake调用类