rt,在课程代码编译中出现了这样的CMake报错,之前曾经在虚拟机里也出现过 当时直接通过重新安装一次解决的,这次是发生在双系统不方便重新安装了,在网上搜索报错也没有明确的解决方案,于是改为搜索提供的解决方案“Add..”,查找到相关资料如下:

https://blog.csdn.net/sawwds/article/details/127777683,即原因三小鱼自动安装时可能没将ros2 的文件source进入 root文件的~/.bashrc中,

//路径因人而异
source /opt/ros/foxy/setup.bash

--- stderr: learning_interface                                          
CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "Findament_cmake.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "ament_cmake", but CMake did not find one.

  Could not find a package configuration file provided by "ament_cmake" with
  any of the following names:

    ament_cmakeConfig.cmake
    ament_cmake-config.cmake

  Add the installation prefix of "ament_cmake" to CMAKE_PREFIX_PATH or set
  "ament_cmake_DIR" to a directory containing one of the above files.  If
  "ament_cmake" provides a separate development package or SDK, be sure it
  has been installed.


---
Failed   <<< learning_interface [1.90s, exited with code 1]
Aborted  <<< learning_pkg_c [1.84s]
Aborted  <<< learning_node [2.33s]                                        
Aborted  <<< learning_pkg_python [2.33s]
Aborted  <<< learning_gazebo [2.55s]                                      
Aborted  <<< learning_launch [2.55s]
Aborted  <<< learning_parameter [2.56s]                                      
Aborted  <<< learning_qos [2.55s]

Summary: 0 packages finished [2.87s]
  1 package failed: learning_interface
  7 packages aborted: learning_gazebo learning_launch learning_node learning_parameter learning_pkg_c learning_pkg_python learning_qos
  2 packages had stderr output: learning_interface learning_pkg_c
  5 packages not processed
复制