有很多与此相关的问题,但我找不到任何对我有用的东西。我创建了一个c++脚本来订阅相机主题。当我试图运行这个脚本时,我得到了以下错误。
receiver.cpp:1:10: fatal error: ros/ros.h: No such file or directory
1 | #include "ros/ros.h"
| ^~~~~~~~~~~
根据我在互联网上的搜索,错误是由于CMake文件造成的。我试过各种方法,都想不出原因。所以我也在下面添加了我的CMake列表文件。请仔细研究一下。
cmake_minimum_required(VERSION 3.0.2)
project(cv_basics)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
include_directories(${OpenCV_INCLUDE_DIRS})
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
rospy
sensor_msgs
std_msgs
nav_msgs
)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
#generate_messages(
# DEPENDENCIES
# sensor_msgs# std_msgs
# )
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES cv_basics
# CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs
# DEPENDS system_lib
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
我使用的是ros noetic和ubuntu 20
发布于 2021-09-15 12:53:46
您需要确保使用CMakeLists.txt
文件中的ros库进行构建。确保您有以下几行代码:
add_executable(some_exe src/your_source.cpp)
target_link_libraries(some_exe ${catkin_LIBRARIES})
当然,请将some_exe
和src/your_source.cpp
替换为其在包中的正确名称。
https://stackoverflow.com/questions/69193014
复制相似问题