小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
视频2.3
-
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_find_dependencies
是一个未知的 CMake 命令。这通常意味着你的 CMakeLists.txt 文件中尝试调用了一个不存在的命令,或者相关的 CMake 模块没有被正确包含或安装。在 ROS 2 环境中,
ament_find_dependencies
是ament_cmake
包的一部分,用于处理依赖关系。这个错误可能由以下几个原因引起:-
ament_cmake 没有被正确安装:虽然错误日志显示找到了
ament_cmake
(版本 1.3.10),但可能某些组件没有正确安装或配置。 -
CMakeLists.txt 文件中的错误:可能是 CMakeLists.txt 文件中的语法错误,或者
ament_find_dependencies
命令的使用方式不正确。 -
环境配置问题:可能是因为环境变量没有正确设置,导致 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 安装或寻求社区的帮助。
以上为生成回答,仅供参考~
-
-
@yfm CMAKELISTS贴一下
-
此回复已被删除! -
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()
-
-
@小鱼 下面是我又重头开始创建的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".