无法在ROS中包含仅包含头文件的库

huangapple go评论50阅读模式
英文:

Unable to include a header-only library in ROS

问题

我有以下项目结构:

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 "
)

而在 graph 内部的 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)

graphpackage.xml 包含以下相关标签:

<depend>utils</depend>

我的错误消息是:

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

你知道我在这里做错了吗?

英文:

I have the following project structure:

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

I am trying to use image_utils.h in graph.cpp.

The CMakelists inside utils looks like this:

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 &quot;*.h&quot;
)

And in the CMakelists inside graph i call find_package(catkin REQUIRED COMPONENTS roscpp) as seen below:

cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)

set(CMAKE_BUILD_TYPE &quot;Release&quot;)
set(CMAKE_CXX_FLAGS &quot;-std=c++11&quot;)

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)

The package.xml of graph has the following relevant tag:

&lt;depend&gt;utils&lt;/depend&gt;

My error message is:

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

Any idea what I am doing wrong here?

答案1

得分: 0

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

英文:

You need to rearrange your folder structure to utils/include/utils/image_utils.h and then also add an add_library(...) call in your CMakeLists.txt file.

答案2

得分: 0

这是你的 CMakelists 文件的中文翻译:

utils:

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"
)

graph:

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})
英文:

Finally figured it out. Here are my CMakelists files:

utils:

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 &quot;*.h&quot;
)

graph:

cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)

set(CMAKE_BUILD_TYPE &quot;Release&quot;)
set(CMAKE_CXX_FLAGS &quot;-std=c++11&quot;)

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})

huangapple
  • 本文由 发表于 2023年2月9日 00:54:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定