c++ - 致命错误:ros/ros.h:没有这样的文件或目录 1 | #include "ros/ros.h"
问题描述
有很多与此相关的问题,但我找不到任何对我有用的东西。我创建了一个 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
推荐阅读
- node.js - 无法将文件上传到 Node.js,使用 Multer 表示后端
- python - 关于将float转换为0和1错误的问题
- python - 如何在 pipenv 环境中处理 `pip install`(不反映在 Pipfile 中,仅反映在 `pipenv graph` 中)?
- python - discord.py 如何制作 requirements.txt
- javascript - 我需要帮助将 jquery 转换为普通的 javascript
- r - xaringan中的“增量方程”?
- javascript - Dropbox Api 教程“错误:找不到模块”
- java - Java 覆盖泛型方法
- windows - 运行程序时触发程序兼容性助手的原因
- python - TypeError: unhashable type: 'numpy.ndarray' 尝试将两个 numpy.ndarrays 转换为字典时