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

    2.3cpp代码

    已定时 已固定 已锁定 已移动
    ROS2机器人开发:从入门到实践
    ros2 cmake报错
    2
    4
    314
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 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_cmake_cppcheck 的配置时发生的,该模块是用于集成 cppcheck 静态代码分析工具到 ROS 2 项目的构建系统中。

        错误信息指出:

        RegularExpression::compile(): Nested ?+.
        RegularExpression::compile(): Error in compile.
        

        这通常意味着正则表达式中包含了不被支持的语法或者格式错误。在这种情况下,错误的正则表达式似乎是尝试匹配文件路径,但包含了不正确的转义字符或格式。

        错误日志中显示了几个试图编译但失败的正则表达式,例如:

        "^/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/."
        "^$&lt;.:/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.*&gt;$"
        

        第二个正则表达式中明显包含了错误的 HTML 实体转义(&lt; 和 &gt;),这看起来是一个格式化或编码错误。

        解决步骤

        1. 检查 CMakeLists.txt:
          确保你的 CMakeLists.txt 文件中没有包含或引用错误的正则表达式。特别是检查与 ament_cmake_cppcheck 相关的配置部分。

        2. 检查 ament_cmake_cppcheck 的版本和配置:
          这个错误可能是由于 ament_cmake_cppcheck 的一个 bug 导致的。尝试更新到最新版本,或者查看该项目的 issue 跟踪器看是否有其他用户报告了类似问题。

        3. 禁用 cppcheck:
          如果你目前不需要 cppcheck,可以临时禁用它以绕过这个问题。在你的 CMakeLists.txt 中找到相关的配置并注释掉或移除。

        4. 清理并重新构建:
          在做出更改后,确保清理旧的构建文件(make clean 或手动删除 build 目录),然后重新运行 CMake。

        5. 查看详细的 CMake 输出:
          检查 CMakeOutput.log 和 CMakeError.log 以获取更多关于错误的信息,这可能帮助你更准确地定位问题。

        6. ROS 社区和论坛:
          如果问题依然存在,考虑在 ROS 的官方论坛或社区中寻求帮助。

        通过上述步骤,你应该能够诊断并解决这个 CMake 配置过程中出现的问题。


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

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

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

          @小伊 yfm@yfm-virtual-machine:~/ros_learn/chapter2/C++/demo_cpp-pkg/build$ cmake ../
          -- The C compiler identification is GNU 11.4.0
          -- The CXX compiler identification is GNU 11.4.0
          -- Detecting C compiler ABI info
          -- Detecting C compiler ABI info - done
          -- Check for working C compiler: /usr/bin/cc - skipped
          -- Detecting C compile features
          -- Detecting C compile features - done
          -- Detecting CXX compiler ABI info
          -- Detecting CXX compiler ABI info - done
          -- Check for working CXX compiler: /usr/bin/c++ - skipped
          -- Detecting CXX compile features
          -- Detecting CXX compile features - done
          -- Found ament_cmake: 1.3.10 (/opt/ros/humble/share/ament_cmake/cmake)
          -- Found Python3: /usr/bin/python3 (found version "3.10.12") found components: Interpreter
          -- 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)
          -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
          -- Found FastRTPS: /opt/ros/humble/include
          -- Using RMW implementation 'rmw_fastrtps_cpp' as default
          -- Looking for pthread.h
          -- Looking for pthread.h - found
          -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
          -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
          -- Found Threads: TRUE
          -- 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_cmake_cppcheck模块中,该模块用于在构建ROS 2包时执行静态代码分析(cppcheck)。错误提示表明在编译正则表达式时遇到了问题,具体是“Nested ?+”这样的错误,这通常意味着正则表达式中有语法错误或者不被支持的特性。

            这里有几个可能的解决步骤:

            1. 检查CMakeLists.txt文件:
              确保您的CMakeLists.txt文件中关于cppcheck的配置部分没有错误。特别是检查是否有任何自定义的cppcheck排除规则或包含目录,这些规则可能使用了不正确的正则表达式。

            2. 更新或修复ament_cmake_cppcheck:
              可能是ament_cmake_cppcheck包本身存在问题。尝试更新ROS 2环境到最新版本,或者检查是否有关于这个包的已知问题。

            3. 禁用cppcheck:
              如果您暂时不需要cppcheck,可以在CMake配置时禁用它。这可以通过在CMake命令行中添加-DAMENT_CMAKE_CPPCHECK=OFF来实现,或者在CMakeLists.txt中设置相应的选项。

            4. 检查CMake和cppcheck版本:
              确保您的CMake和cppcheck版本与ROS 2版本兼容。有时候,软件更新后可能会引入不兼容的更改。

            5. 查看CMakeOutput.log:
              查看CMakeOutput.log文件可能会提供更多关于配置失败的信息。这可以帮助您更准确地定位问题。

            6. 手动运行cppcheck:
              尝试在命令行中手动运行cppcheck,看看是否能成功执行,或者是否有更具体的错误信息。

            7. 检查路径和文件名:
              确保您的项目路径和文件名中没有特殊字符或非常长的路径,这有时会导致正则表达式解析问题。

            如果上述步骤都不能解决问题,您可能需要更详细地检查ament_cmake_cppcheck的源代码或寻求ROS社区的帮助。


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

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

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