小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
cmake找不到rosidl_typesupport_c
-
cmake_minimum_required(VERSION 3.8) project(village_wang) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() set(CMAKE_PREFIX_PATH "/opt/ros/humble") # find dependencies find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() ament_package()
cmake配置文件运行时找不到rosidl_typesupport_c包,ament_cmake这个可以找到
cmake报错CMake Error at /opt/ros/humble/share/rosidl_typesupport_c/cmake/get_used_typesupports.cmake:35 (message): No 'rosidl_typesupport_c' found Call Stack (most recent call first): /opt/ros/humble/share/rosidl_typesupport_c/cmake/rosidl_typesupport_c-extras.cmake:8 (get_used_typesupports) /opt/ros/humble/share/rosidl_typesupport_c/cmake/rosidl_typesupport_cConfig.cmake:41 (include) /opt/ros/humble/share/builtin_interfaces/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/builtin_interfaces/cmake/builtin_interfacesConfig.cmake:41 (include) /opt/ros/humble/share/libstatistics_collector/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/libstatistics_collector/cmake/libstatistics_collectorConfig.cmake:41 (include) /opt/ros/humble/share/rclcpp/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/rclcpp/cmake/rclcppConfig.cmake:41 (include) CMakeLists.txt:12 (find_package) -- Configuring incomplete, errors occurred!``` code_text
-
从您提供的错误信息来看,CMake 在配置过程中未能找到
rosidl_typesupport_c
包。这通常意味着rosidl_typesupport_c
包的路径没有被正确地添加到 CMake 的搜索路径中,或者该包并未被正确安装。这里有几个步骤可以帮助您解决这个问题:
-
确认
rosidl_typesupport_c
是否已安装:
确保rosidl_typesupport_c
包已经在您的 ROS 2 环境中正确安装。您可以通过运行以下命令来检查:dpkg -l | grep rosidl-typesupport-c
如果此命令没有返回任何结果,那么您可能需要安装它。在 ROS 2 Humble 中,您可以使用以下命令安装:
sudo apt install ros-humble-rosidl-typesupport-c
-
检查
CMAKE_PREFIX_PATH
:
您已经在 CMakeLists.txt 中设置了CMAKE_PREFIX_PATH
为/opt/ros/humble
,这是正确的。但是,确保这个路径确实包含了所有需要的 ROS 2 包。通常,如果您是通过 ROS 2 的官方安装脚本或包管理器安装的,那么包应该位于这个路径下。 -
检查 CMakeLists.txt 中的依赖查找:
您的 CMakeLists.txt 中使用了find_package
来查找依赖,但是对于rosidl_typesupport_c
,通常它应该是作为其他包的依赖而被间接找到的。如果您直接需要找到并使用rosidl_typesupport_c
,请确保它已经在您的项目中作为依赖被声明(虽然通常这是通过其他 ROS 2 包如rclcpp
自动处理的)。 -
清理并重新构建:
有时候,旧的构建文件可能会导致问题。尝试清理您的构建目录(通常是build
文件夹),然后重新运行 CMake。 -
检查环境变量:
确保您的source /opt/ros/humble/setup.bash
(或对应的 shell 初始化脚本)已经执行,这会将 ROS 2 的环境变量设置正确。 -
查看详细的 CMake 输出:
运行 CMake 时添加-DCMAKE_VERBOSE_MAKEFILE=ON
选项,这将显示更多的详细信息,可能会帮助您诊断问题。
如果上述步骤都不能解决问题,您可能需要检查是否有其他配置或安装问题,或者查看 ROS 2 社区或相关论坛寻求帮助。
以上为生成回答,仅供参考~
-
-
@starRiver-lea 在 cmake找不到rosidl_typesupport_c 中说:
set(CMAKE_PREFIX_PATH "/opt/ros/humble")
这个路径不对,你还是下source 改环境变量
-
@小鱼 感谢您的回答,我只在/opt/ros/humble路径下面找到了setup.bash,使用wget http://fishros.com/install -O fishros && . fishros
命令安装的正确路径应该是什么 -
@starRiver-lea 先 source /opt/ros/humble/setup.bash 接着执行 cmake
-
@小鱼 执行完source /opt/ros/humble/setup.bash命令后仍然报错
/snap/clion/296/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/snap/clion/296/bin/ninja/linux/x64/ninja -G Ninja -S /home/lfy/workspace/ros2/village_wang -B /home/lfy/workspace/ros2/village_wang/cmake-build-debug -- Found ament_cmake: 1.3.10 (/opt/ros/humble/share/ament_cmake/cmake) -- Found rclcpp: 16.0.10 (/opt/ros/humble/share/rclcpp/cmake) -- Found rosidl_generator_c: 3.1.5 (/opt/ros/humble/share/rosidl_generator_c/cmake) -- Found rosidl_adapter: 3.1.5 (/opt/ros/humble/share/rosidl_adapter/cmake) -- Found rosidl_generator_cpp: 3.1.5 (/opt/ros/humble/share/rosidl_generator_cpp/cmake) CMake Error at /opt/ros/humble/share/rosidl_typesupport_c/cmake/get_used_typesupports.cmake:35 (message): No 'rosidl_typesupport_c' found Call Stack (most recent call first): /opt/ros/humble/share/rosidl_typesupport_c/cmake/rosidl_typesupport_c-extras.cmake:8 (get_used_typesupports) /opt/ros/humble/share/rosidl_typesupport_c/cmake/rosidl_typesupport_cConfig.cmake:41 (include) /opt/ros/humble/share/builtin_interfaces/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/builtin_interfaces/cmake/builtin_interfacesConfig.cmake:41 (include) /opt/ros/humble/share/libstatistics_collector/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/libstatistics_collector/cmake/libstatistics_collectorConfig.cmake:41 (include) /opt/ros/humble/share/rclcpp/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package) /opt/ros/humble/share/rclcpp/cmake/rclcppConfig.cmake:41 (include) CMakeLists.txt:12 (find_package) -- Configuring incomplete, errors occurred! [无法重新加载]
-
@starRiver-lea 在文件中能找到rosidl_typesupport_c这个包