@小鱼 下面是我又重头开始创建的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".