小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
2.3cpp代码
-
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". -
从你提供的错误信息来看,问题出在 CMake 配置过程中尝试编译一个正则表达式时失败了。这个错误具体是在处理
ament_cmake_cppcheck
的配置时发生的,该模块是用于集成cppcheck
静态代码分析工具到 ROS 2 项目的构建系统中。错误信息指出:
RegularExpression::compile(): Nested ?+. RegularExpression::compile(): Error in compile.
这通常意味着正则表达式中包含了不被支持的语法或者格式错误。在这种情况下,错误的正则表达式似乎是尝试匹配文件路径,但包含了不正确的转义字符或格式。
错误日志中显示了几个试图编译但失败的正则表达式,例如:
"^/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/." "^$<.:/home/yfm/ros_learn/chapter2/C++/demo_cpp-pkg/.*>$"
第二个正则表达式中明显包含了错误的 HTML 实体转义(
<
和>
),这看起来是一个格式化或编码错误。解决步骤
-
检查 CMakeLists.txt:
确保你的CMakeLists.txt
文件中没有包含或引用错误的正则表达式。特别是检查与ament_cmake_cppcheck
相关的配置部分。 -
检查 ament_cmake_cppcheck 的版本和配置:
这个错误可能是由于ament_cmake_cppcheck
的一个 bug 导致的。尝试更新到最新版本,或者查看该项目的 issue 跟踪器看是否有其他用户报告了类似问题。 -
禁用 cppcheck:
如果你目前不需要cppcheck
,可以临时禁用它以绕过这个问题。在你的CMakeLists.txt
中找到相关的配置并注释掉或移除。 -
清理并重新构建:
在做出更改后,确保清理旧的构建文件(make clean
或手动删除build
目录),然后重新运行 CMake。 -
查看详细的 CMake 输出:
检查CMakeOutput.log
和CMakeError.log
以获取更多关于错误的信息,这可能帮助你更准确地定位问题。 -
ROS 社区和论坛:
如果问题依然存在,考虑在 ROS 的官方论坛或社区中寻求帮助。
通过上述步骤,你应该能够诊断并解决这个 CMake 配置过程中出现的问题。
以上为生成回答,仅供参考~
-
-
@小伊 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". -
从您提供的CMake配置错误信息来看,问题主要出现在
ament_cmake_cppcheck
模块中,该模块用于在构建ROS 2包时执行静态代码分析(cppcheck)。错误提示表明在编译正则表达式时遇到了问题,具体是“Nested ?+”这样的错误,这通常意味着正则表达式中有语法错误或者不被支持的特性。这里有几个可能的解决步骤:
-
检查CMakeLists.txt文件:
确保您的CMakeLists.txt
文件中关于cppcheck的配置部分没有错误。特别是检查是否有任何自定义的cppcheck排除规则或包含目录,这些规则可能使用了不正确的正则表达式。 -
更新或修复ament_cmake_cppcheck:
可能是ament_cmake_cppcheck
包本身存在问题。尝试更新ROS 2环境到最新版本,或者检查是否有关于这个包的已知问题。 -
禁用cppcheck:
如果您暂时不需要cppcheck,可以在CMake配置时禁用它。这可以通过在CMake命令行中添加-DAMENT_CMAKE_CPPCHECK=OFF
来实现,或者在CMakeLists.txt
中设置相应的选项。 -
检查CMake和cppcheck版本:
确保您的CMake和cppcheck版本与ROS 2版本兼容。有时候,软件更新后可能会引入不兼容的更改。 -
查看CMakeOutput.log:
查看CMakeOutput.log
文件可能会提供更多关于配置失败的信息。这可以帮助您更准确地定位问题。 -
手动运行cppcheck:
尝试在命令行中手动运行cppcheck,看看是否能成功执行,或者是否有更具体的错误信息。 -
检查路径和文件名:
确保您的项目路径和文件名中没有特殊字符或非常长的路径,这有时会导致正则表达式解析问题。
如果上述步骤都不能解决问题,您可能需要更详细地检查
ament_cmake_cppcheck
的源代码或寻求ROS社区的帮助。
以上为生成回答,仅供参考~
-