有很多与此相关的问题,但我找不到任何对我有用的。我创建了一个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
您需要确保您正在使用CMakeLists.txt
文件中的ros库进行构建。确保你有这些行:
add_executable(some_exe src/your_source.cpp)
target_link_libraries(some_exe ${catkin_LIBRARIES})
当然,将some_exe
和src/your_source.cpp
替换为您的包中的正确名称。