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

    视频2.3

    已定时 已固定 已锁定 已移动
    ROS2机器人开发:从入门到实践
    章节2.3; amenttarget ros2
    3
    7
    391
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Y
      yfm
      最后由 yfm 编辑

      cmake时候报错:
      yfm@yfm-virtual-machine:~/ros_learn/chapter2/C++/demo_cpp-pkg/build$ cmake ../
      -- 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)
      -- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
      -- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
      -- Found rmw_implementation_cmake: 6.1.2 (/opt/ros/humble/share/rmw_implementation_cmake/cmake)
      -- Found rmw_fastrtps_cpp: 6.2.7 (/opt/ros/humble/share/rmw_fastrtps_cpp/cmake)
      -- Using RMW implementation 'rmw_fastrtps_cpp' as default
      -- Found ament_lint_auto: 0.12.11 (/opt/ros/humble/share/ament_lint_auto/cmake)
      -- Added test 'cppcheck' to perform static code analysis on C / C++ code
      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.
      ".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^$<.
      :/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.*>$".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.
      ".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^$<.
      :/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.*>$".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.
      ".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      RegularExpression::compile(): Nested ?+.
      RegularExpression::compile(): Error in compile.
      CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
      string sub-command REGEX, mode MATCH failed to compile regex
      "^$<.
      :/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.*>$".
      Call Stack (most recent call first):
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
      /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
      CMakeLists.txt:30 (ament_package)

      -- Configured cppcheck include dirs:
      -- Configured cppcheck exclude dirs and/or files:
      -- Added test 'lint_cmake' to check CMake code style
      -- Added test 'uncrustify' to check C / C++ code style
      -- Configured uncrustify additional arguments:
      -- Added test 'xmllint' to check XML markup files
      -- Configuring incomplete, errors occurred!
      See also "/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/build/CMakeFiles/CMakeOutput.log".

      小鱼小 1 条回复 最后回复 回复 引用 0
      • 小伊小
        机器人小伊
        最后由 编辑

        错误消息显示,在 CMake 构建过程中遇到了一个问题:ament_find_dependencies 是一个未知的 CMake 命令。这通常意味着你的 CMakeLists.txt 文件中尝试调用了一个不存在的命令,或者相关的 CMake 模块没有被正确包含或安装。

        在 ROS 2 环境中,ament_find_dependencies 是 ament_cmake 包的一部分,用于处理依赖关系。这个错误可能由以下几个原因引起:

        1. ament_cmake 没有被正确安装:虽然错误日志显示找到了 ament_cmake(版本 1.3.10),但可能某些组件没有正确安装或配置。

        2. CMakeLists.txt 文件中的错误:可能是 CMakeLists.txt 文件中的语法错误,或者 ament_find_dependencies 命令的使用方式不正确。

        3. 环境配置问题:可能是因为环境变量没有正确设置,导致 CMake 无法找到 ament_cmake 的相关组件。

        为了解决这个问题,你可以尝试以下几个步骤:

        1. 确认 ament_cmake 已正确安装

        确保你的 ROS 2 环境已经正确安装,并且 ament_cmake 也在其中。你可以通过运行 ros2 pkg list | grep ament_cmake 来检查 ament_cmake 是否已安装。

        2. 检查 CMakeLists.txt

        • 确保你的 CMakeLists.txt 文件顶部包含了 find_package(ament_cmake REQUIRED)。
        • 检查 ament_find_dependencies 的使用是否正确,它通常应该像这样使用:ament_find_dependencies(DEPENDENCIES <dependency1> <dependency2> ...)。

        3. 重新配置环境

        • 确保你的 shell 环境已经加载了 ROS 2 的 setup.bash。你可以通过在你的 shell 中运行 source /opt/ros/humble/setup.bash 来手动加载。
        • 重新启动你的终端或重新加载你的 shell 配置文件(如 .bashrc 或 .zshrc),以确保所有环境变量都是最新的。

        4. 清理并重新构建

        • 在你的构建目录(例如 build)中,运行 make clean(如果可用)来清理旧的构建文件。
        • 从你的源代码目录重新运行 cmake .. 和 make。

        如果上述步骤仍然无法解决问题,可能需要更详细地检查你的 ROS 2 安装或寻求社区的帮助。


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

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

        1 条回复 最后回复 回复 引用 0
        • 小鱼小
          小鱼 技术大佬 @yfm
          最后由 编辑

          @yfm CMAKELISTS贴一下

          新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

          Y 2 条回复 最后回复 回复 引用 0
          • Y
            yfm @小鱼
            最后由 编辑

            此回复已被删除!
            1 条回复 最后回复 回复 引用 0
            • Y
              yfm @小鱼
              最后由 编辑

              @小鱼

              cmake_minimum_required(VERSION 3.8)
              project(demo_cpp-pkg)
              
              if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
                add_compile_options(-Wall -Wextra -Wpedantic)
              endif()
              
              add_executable(cpp_node src/cpp_node.cpp)
              
              # find dependencies
              find_package(ament_cmake REQUIRED)
              find_package(rclcpp REQUIRED)
              # uncomment the following section in order to fill in
              # further dependencies manually.
              # find_package(<dependency> REQUIRED)
              ament_target_dependencies(cpp_node rclcpp)
              
              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()
              
              
              小鱼小 1 条回复 最后回复 回复 引用 0
              • 小鱼小
                小鱼 技术大佬 @yfm
                最后由 编辑

                @yfm 在 视频2.3 中说:

                add_executable(cpp_node src/cpp_node.cpp)

                这句话写错位置了,放到if上面

                @yfm 在 视频2.3 中说:

                if(BUILD_TESTING)

                新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                Y 1 条回复 最后回复 回复 引用 0
                • Y
                  yfm @小鱼
                  最后由 编辑

                  @小鱼 下面是我又重头开始创建的workspace然后写的CMakeLists.txt

                  cmake_minimum_required(VERSION 3.8)
                  project(demo_cpp_node_pkg)
                  
                  if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
                    add_compile_options(-Wall -Wextra -Wpedantic)
                  endif()
                  
                  # find dependencies
                  find_package(ament_cmake REQUIRED)
                  find_package(rclcpp REQUIRED)
                  # uncomment the following section in order to fill in
                  # further dependencies manually.
                  # find_package(<dependency> REQUIRED)
                  
                  
                  
                  #target_include_directories(cpp_node_test PUBLIC ${rclcpp_INCLUDE_DIRS})
                  
                  #target_link_libraries(cpp_node_test ${rclcpp_LIBRARIES})
                  
                  
                  
                  add_executable(cpp_node_test src/cpp_node_test.cpp)
                  ament_target_dependencies(cpp_node_test rclcpp)
                  
                  
                  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()
                  
                  

                  然后报错如下:

                  yfm@yfm-virtual-machine:~/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/build$ cmake ../
                  -- 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)
                  -- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
                  -- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
                  -- Found rmw_implementation_cmake: 6.1.2 (/opt/ros/humble/share/rmw_implementation_cmake/cmake)
                  -- Found rmw_fastrtps_cpp: 6.2.7 (/opt/ros/humble/share/rmw_fastrtps_cpp/cmake)
                  -- Using RMW implementation 'rmw_fastrtps_cpp' as default
                  -- Found ament_lint_auto: 0.12.11 (/opt/ros/humble/share/ament_lint_auto/cmake)
                  -- Added test 'cppcheck' to perform static code analysis on C / C++ code
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^\$<.*:/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*>$".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^\$<.*:/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*>$".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:73 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  RegularExpression::compile(): Nested *?+.
                  RegularExpression::compile(): Error in compile.
                  CMake Error at /opt/ros/humble/share/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake:75 (string):
                    string sub-command REGEX, mode MATCH failed to compile regex
                    "^\$<.*:/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/.*>$".
                  Call Stack (most recent call first):
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_lint_auto/cmake/ament_lint_auto_package_hook.cmake:21 (ament_execute_extensions)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
                    /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions)
                    CMakeLists.txt:38 (ament_package)
                  
                  
                  -- Configured cppcheck include dirs: 
                  -- Configured cppcheck exclude dirs and/or files: 
                  -- Added test 'lint_cmake' to check CMake code style
                  -- Added test 'uncrustify' to check C / C++ code style
                  -- Configured uncrustify additional arguments: 
                  -- Added test 'xmllint' to check XML markup files
                  -- Configuring incomplete, errors occurred!
                  See also "/home/yfm/ros_learn/C++/chapter_ws/demo_cpp_node_pkg/build/CMakeFiles/CMakeOutput.log".
                  
                  1 条回复 最后回复 回复 引用 0
                  • 第一个帖子
                    最后一个帖子
                  皖ICP备16016415号-7
                  Powered by NodeBB | 鱼香ROS