英文:
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)
graph
的 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"
^~~~~~~~~~~~~~~~~~~~~
你知道我在这里做错了吗?
英文:
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 "*.h"
)
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 "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)
The package.xml
of graph has the following relevant tag:
<depend>utils</depend>
My error message is:
graph.cpp:12:10: fatal error: utils/image_utils.h: No such file or directory
#include "utils/image_utils.h"
^~~~~~~~~~~~~~~~~~~~~
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 "*.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})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论