鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    Cmake报错,如何解决?

    已定时 已固定 已锁定 已移动 未解决
    综合问题
    cmake报错 ros2
    2
    4
    518
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • D
      Darran
      最后由 编辑

      CMakeLists.txt代码如下(跟着书本敲写):

      cmake_minimum_required(VERSION 3.8)
      project(ros2_cpp_node)
      add_executable(ros2_cpp_node ros2_cpp_node.cpp)
      find_package(rclcpp REQUIRED)
      find_package(std_msgs REQUIRED)
      target_include_directories(ros2_cpp_node PUBLIC ${rclcpp_INCLUDE_DIRS})
      target_link_libraries(ros2_cpp_node ${rclcpp_LIBRARIES})
      

      环境检查如下:

      jetson@unbutu:~/Documents/chapt2$ echo $CMAKE_PREFIX_PATH
      /opt/ros/foxy
      jetson@unbutu:~/Documents/chapt2$ echo $AMENT_PREFIX_PATH
      /opt/ros/foxy
      

      cmake . 终端输出如下:

      jetson@unbutu:~/Documents/chapt2$ cmake .
      -- Found ament_cmake: 0.9.12 (/opt/ros/foxy/share/ament_cmake/cmake)
      -- Using PYTHON_EXECUTABLE: /usr/bin/python3
      -- Found rclcpp: 2.4.3 (/opt/ros/foxy/share/rclcpp/cmake)
      -- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
      -- Found rosidl_adapter: 1.3.1 (/opt/ros/foxy/share/rosidl_adapter/cmake)
      -- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
      -- Found rmw_implementation_cmake: 1.0.4 (/opt/ros/foxy/share/rmw_implementation_cmake/cmake)
      -- Using RMW implementation 'rmw_fastrtps_cpp' as default
      -- Configuring done
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_c" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_c" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_generator_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_introspection_cpp" but the target
        was not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "std_msgs::std_msgs__rosidl_typesupport_cpp" but the target was not found.
        Perhaps a find_package() call is missing for an IMPORTED target, or an
        ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_generator_c" but the target was not
        found.  Perhaps a find_package() call is missing for an IMPORTED target, or
        an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_typesupport_introspection_c" but the
        target was not found.  Perhaps a find_package() call is missing for an
        IMPORTED target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_typesupport_c" but the target was not
        found.  Perhaps a find_package() call is missing for an IMPORTED target, or
        an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_generator_cpp" but the target was not
        found.  Perhaps a find_package() call is missing for an IMPORTED target, or
        an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_typesupport_introspection_cpp" but
        the target was not found.  Perhaps a find_package() call is missing for an
        IMPORTED target, or an ALIAS target is missing?
      
      
      CMake Error at CMakeLists.txt:10 (add_executable):
        Target "ros2_cpp_node" links to target
        "rosgraph_msgs::rosgraph_msgs__rosidl_typesupport_cpp" but the target was
        not found.  Perhaps a find_package() call is missing for an IMPORTED
        target, or an ALIAS target is missing?
      
      
      -- Generating done
      CMake Generate step failed.  Build files cannot be regenerated correctly.
      
      D 1 条回复 最后回复 回复 引用 0
      • 小伊小
        机器人小伊
        最后由 编辑

        从你提供的CMake输出信息来看,问题在于CMake无法找到std_msgs和rosgraph_msgs中的某些目标(targets),这些目标是由ROS 2的消息生成系统创建的。这通常意味着CMake在配置过程中没有正确地找到或处理这些消息包。

        解决步骤:

        1. 确保消息包已安装:
          首先,确保std_msgs和rosgraph_msgs包已经正确安装在你的ROS 2环境中。你可以通过运行以下命令来安装它们(如果尚未安装):

          sudo apt install ros-foxy-std-msgs ros-foxy-rosgraph-msgs
          
        2. 检查ament_index:
          ROS 2使用ament_index来管理和查找安装的包。确保ament_index是最新的,并且包含了所有必要的包。通常,安装或更新ROS 2包会自动处理这个问题,但有时可能需要手动更新索引:

          source /opt/ros/foxy/setup.bash
          ros2 pkg update
          
        3. 检查CMakeLists.txt:
          你的CMakeLists.txt看起来基本正确,但通常不需要手动设置include目录和链接库,因为find_package应该处理这些。确保你的CMakeLists.txt使用了正确的ament_package()和find_package()调用。例如:

          cmake_minimum_required(VERSION 3.5)
          project(ros2_cpp_node)
          
          find_package(ament_cmake REQUIRED)
          find_package(rclcpp REQUIRED)
          find_package(std_msgs REQUIRED)
          
          add_executable(ros2_cpp_node src/ros2_cpp_node.cpp)
          ament_target_dependencies(ros2_cpp_node rclcpp std_msgs)
          
          install(TARGETS
            ros2_cpp_node
            DESTINATION lib/${PROJECT_NAME})
          
          ament_package()
          

          注意,这里使用了ament_target_dependencies来添加依赖,这是ROS 2推荐的方式。

        4. 清理并重新构建:
          在进行了上述更改后,确保清理旧的构建文件并重新运行CMake:

          rm -rf build/
          mkdir build/
          cd build/
          cmake ..
          make
          
        5. 检查环境变量:
          你已经检查了CMAKE_PREFIX_PATH和AMENT_PREFIX_PATH,确保它们包含了ROS 2的安装路径。通常,只需设置CMAKE_PREFIX_PATH就足够了。

        6. 查看详细输出:
          如果问题仍然存在,尝试在CMake命令中添加-DCMAKE_VERBOSE_MAKEFILE=ON来获取更详细的输出,这可能会帮助诊断问题。

        通过上述步骤,你应该能够解决CMake配置过程中遇到的问题。如果问题仍然存在,可能需要检查ROS 2的安装是否完整或考虑重新安装ROS 2。


        以上为生成回答,仅供参考~

        我是小伊,已接入ChatGpt,所有回复,仅供参考~

        1 条回复 最后回复 回复 引用 0
        • D
          Darran @Darran
          最后由 编辑

          @Darran 定位到报错信息出在

          target_link_libraries(ros2_cpp_node ${rclcpp_LIBRARIES})
          

          不知道咋解决!

          D 1 条回复 最后回复 回复 引用 0
          • D
            Darran @Darran
            最后由 编辑

            @小鱼 有时间可以帮忙看看吗

            1 条回复 最后回复 回复 引用 0
            • 第一个帖子
              最后一个帖子
            皖ICP备16016415号-7
            Powered by NodeBB | 鱼香ROS