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

    请问ros2在使用make编译的时候报这个错误是怎么回事儿阿?

    已定时 已固定 已锁定 已移动
    动手学ROS2
    ros2 linux ros编译
    3
    3
    399
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • L
      luyuan
      最后由 编辑

      .cpp file
      #include "rclcpp/rclcpp.hpp"

      int main(int argc, char** argv)
      {
      rclcpp::init(argc, argv);
      auto node = std::make_sharedrclcpp::Node("test_node");
      RCLCPP_INFO(node->get_logger(), "Hello, ROS2!");
      rclcpp::spin(node);
      rclcpp::shutdown();
      return 0;
      }

      cmakelists.txt
      cmake_minimum_required(VERSION 3.20)
      project(test_node)
      add_executable(test_node test_node.cpp)

      find_package(rclcpp REQUIRED)

      target_include_directories(test_node PUBLIC ${rclcpp_INCLUDE_DIRS})
      target_link_libraries(test_node ${rclcpp_LIBRARIES})

      In file included from /opt/ros/humble/include/rclcpp/rclcpp/publisher.hpp:42:0,
      from /opt/ros/humble/include/rclcpp/rclcpp/topic_statistics/subscription_topic_statistics.hpp:31,
      from /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:50,
      from /opt/ros/humble/include/rclcpp/rclcpp/any_executable.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategy.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategies.hpp:18,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor_options.hpp:20,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor.hpp:37,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors.hpp:21,
      from /opt/ros/humble/include/rclcpp/rclcpp/rclcpp.hpp:155,
      from /home/luyuan/桌面/all_codes/ros2_learn/test_node.cpp:1:
      /opt/ros/humble/include/rclcpp/rclcpp/publisher_options.hpp:69:10: error: ‘is_void_v’ is not a member of ‘std’
      std::is_void_v<typename std::allocator_traits<Allocator>::value_type>,
      ^~~~~~~~~
      /opt/ros/humble/include/rclcpp/rclcpp/publisher_options.hpp:69:10: note: suggested alternative: ‘is_void’
      std::is_void_v<typename std::allocator_traits<Allocator>::value_type>,
      ^~~~~~~~~
      is_void
      /opt/ros/humble/include/rclcpp/rclcpp/publisher_options.hpp:69:73: error: expected ‘(’ before ‘>’ token
      std::is_void_v<typename std::allocator_traits<Allocator>::value_type>,
      ^
      /opt/ros/humble/include/rclcpp/rclcpp/publisher_options.hpp:69:74: error: expected primary-expression before ‘,’ token
      std::is_void_v<typename std::allocator_traits<Allocator>::value_type>,
      ^
      In file included from /opt/ros/humble/include/rclcpp/rclcpp/any_executable.hpp:25:0,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategy.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategies.hpp:18,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor_options.hpp:20,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor.hpp:37,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors.hpp:21,
      from /opt/ros/humble/include/rclcpp/rclcpp/rclcpp.hpp:155,
      from /home/luyuan/桌面/all_codes/ros2_learn/test_node.cpp:1:
      /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:295:10: error: ‘is_same_v’ is not a member of ‘std’
      std::is_same_v<TakeT, SubscribedType>,
      ^~~~~~~~~
      /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:295:10: note: suggested alternative: ‘is_same’
      std::is_same_v<TakeT, SubscribedType>,
      ^~~~~~~~~
      is_same
      /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:293:8: error: parse error in template argument list
      std::enable_if_t<
      ^~~~~~~~~~~~
      !rosidl_generator_traits::is_message<TakeT>::value &&
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      std::is_same_v<TakeT, SubscribedType>,
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:295:42: error: expected unqualified-id before ‘,’ token
      std::is_same_v<TakeT, SubscribedType>,
      ^
      In file included from /opt/ros/humble/include/rclcpp/rclcpp/subscription_base.hpp:32:0,
      from /opt/ros/humble/include/rclcpp/rclcpp/callback_group.hpp:29,
      from /opt/ros/humble/include/rclcpp/rclcpp/any_executable.hpp:20,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategy.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/memory_strategies.hpp:18,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor_options.hpp:20,
      from /opt/ros/humble/include/rclcpp/rclcpp/executor.hpp:37,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25,
      from /opt/ros/humble/include/rclcpp/rclcpp/executors.hpp:21,
      from /opt/ros/humble/include/rclcpp/rclcpp/rclcpp.hpp:155,
      from /home/luyuan/桌面/all_codes/ros2_learn/test_node.cpp:1:
      /opt/ros/humble/include/rclcpp/rclcpp/any_subscription_callback.hpp: In instantiation of ‘class rclcpp::AnySubscriptionCallback<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >’:
      /opt/ros/humble/include/rclcpp/rclcpp/subscription.hpp:423:49: required from ‘class rclcpp::Subscription<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> > >’
      /opt/ros/humble/include/rclcpp/rclcpp/parameter_client.hpp:208:69: required from here
      /opt/ros/humble/include/rclcpp/rclcpp/any_subscription_callback.hpp:977:3: error: no type named ‘variant_type’ in ‘struct rclcpp::detail::AnySubscriptionCallbackHelper<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, false>’
      get_variant()
      ^~~~~~~~~~~
      /opt/ros/humble/include/rclcpp/rclcpp/any_subscription_callback.hpp:983:3: error: no type named ‘variant_type’ in ‘struct rclcpp::detail::AnySubscriptionCallbackHelper<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, false>’
      get_variant() const
      ^~~~~~~~~~~
      /opt/ros/humble/include/rclcpp/rclcpp/any_subscription_callback.hpp:993:34: error: no type named ‘variant_type’ in ‘struct rclcpp::detail::AnySubscriptionCallbackHelper<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, false>’
      typename HelperT::variant_type callback_variant_;
      ^~~~~~~~~~~~~~~~~
      make[2]: *** [CMakeFiles/test_node.dir/build.make:76:CMakeFiles/test_node.dir/test_node.cpp.o] 错误 1
      make[1]: *** [CMakeFiles/Makefile2:85:CMakeFiles/test_node.dir/all] 错误 2
      make: *** [Makefile:101:all] 错误 2

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

        从错误信息来看,你遇到的问题主要与C++标准库中的类型特性(type traits)相关。错误提示表明std::is_void_v和std::is_same_v不是std的成员,这通常意味着编译器没有识别这些类型特性,这可能是因为你的编译器或编译选项不支持C++17或更高版本,而std::is_void_v和std::is_same_v是C++17中引入的。

        ROS 2 Humble 默认要求使用C++17或更高版本的编译器。以下是一些可能的解决步骤:

        1. 检查编译器版本:
          确保你使用的编译器支持C++17。对于GCC,版本应该至少是8.2;对于Clang,版本应该至少是7.0。你可以通过运行gcc --version或clang --version来检查你的编译器版本。

        2. 设置CMake使用C++17:
          在你的CMakeLists.txt文件中,确保设置了正确的C++标准。虽然ROS 2的CMake模板通常已经设置了这一点,但你可以显式地添加或确认以下行:

          set(CMAKE_CXX_STANDARD 17)
          set(CMAKE_CXX_STANDARD_REQUIRED ON)
          
        3. 清理并重新构建:
          在修改CMakeLists.txt或编译器设置后,确保清理你的构建目录(如果有的话)并从头开始构建。这可以通过删除build或CMakeCache.txt文件以及使用make clean(如果可用)来完成,然后再次运行colcon build或cmake .. && make(取决于你使用的是colcon还是传统的make)。

        4. 检查环境变量:
          确保你的环境变量正确设置,特别是与ROS 2和编译器相关的变量。这包括CMAKE_PREFIX_PATH,它应该包含ROS 2的安装路径。

        5. 使用colcon代替make:
          ROS 2推荐使用colcon作为构建系统。如果你的项目是一个标准的ROS 2包,使用colcon build代替make可能更容易解决依赖和构建问题。确保你的工作空间已经正确设置,并且你已经初始化了它(使用colcon build --packages-up-to <package-name>)。

        6. 查看依赖关系:
          确保所有必要的依赖项都已正确安装,并且CMakeLists.txt文件中的find_package调用正确无误。

        如果以上步骤仍然无法解决问题,请检查ROS 2的官方文档或社区论坛,看看是否有其他人遇到并解决了类似的问题。


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

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

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

          @luyuan 看最新版教程

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

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