cmake 无法在ROS中包含仅标题库

wztqucjr  于 2023-02-12  发布在  其他
关注(0)|答案(2)|浏览(125)

我的项目结构如下:

utils 
 include
   utils 
    image_utils.h
 CMakelists.txt
 package.xml
graph
 src
  graph.cpp
 CMakelists.txt
 package.xml

我正在尝试在graph.cpp中使用image_utils.h
utils内部的CMakelists如下所示:

cmake_minimum_required(VERSION 3.0.2)
project(utils)

find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  CATKIN_DEPENDS roscpp 
)
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

add_library(${PROJECT_NAME} INTERFACE)
target_link_libraries(${PROJECT_NAME} INTERFACE ${catkin_LIBRARIES} )

install(
  DIRECTORY include/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
)

CMakelists内部图中,我调用find_package(catkin REQUIRED COMPONENTS roscpp),如下所示:

cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs cv_bridge utils)

find_package(OpenCV 3.4 REQUIRED)

include_directories(${catkin_INCLUDE_DIRS} )
catkin_package(CATKIN_DEPENDS utils)
add_executable(graph src/graph.cpp)
target_link_libraries(graph ${catkin_LIBRARIES} ${OpenCV_LIBS} utils)

图形的package.xml具有以下相关标记:

<depend>utils</depend>

我的错误消息是:

graph.cpp:12:10: fatal error: utils/image_utils.h: No such file or directory
 #include "utils/image_utils.h"
          ^~~~~~~~~~~~~~~~~~~~~

你知道我做错了什么吗?

ccgok5k5

ccgok5k51#

您需要将文件夹结构重新排列为utils/include/utils/image_utils.h,然后在CMakeLists.txt文件中添加一个add_library(...)调用。

watbbzwu

watbbzwu2#

终于找到了。下面是我的CMakelists文件:
效用:

cmake_minimum_required(VERSION 3.0.2)
project(utils)

find_package(catkin REQUIRED COMPONENTS roscpp)

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS roscpp
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

install(
  DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
)

图表:

cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs cv_bridge utils)

find_package(OpenCV 3.4 REQUIRED)

catkin_package(CATKIN_DEPENDS utils)
include_directories(${catkin_INCLUDE_DIRS} )

add_executable(graph src/graph.cpp)

target_link_libraries(graph ${catkin_LIBRARIES} ${OpenCV_LIBS})

相关问题