基于Ubuntu22.04在ROS2 Humble中编译turtlebot3遇到的坑

1. 首先通过一下步骤下载turtlebot3的源码

mkdir -p ~/tb3_ws/src
$ cd ~/tb3_ws
#humble版本
$wget https://raw.githubusercontent.com/ROBOTIS-GIT/turtlebot3/humble-devel/turtlebot3.repos

如果下载失败,可直接编辑该文件(~/tb3_ws/turtlebot3.repos)为如下内容:

repositories:
  turtlebot3/turtlebot3:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3.git
    version: ros2-devel
  turtlebot3/turtlebot3_msgs:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
    version: ros2-devel
  turtlebot3/turtlebot3_simulations:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
    version: ros2-devel
  utils/DynamixelSDK:
    type: git
    url: https://github.com/ROBOTIS-GIT/DynamixelSDK.git
    version: ros2-devel
  utils/hls_lfcd_lds_driver:
    type: git
    url: https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git
    version: ros2-devel
  utils/ld08_driver:
    type: git
    url: https://github.com/ROBOTIS-GIT/ld08_driver.git
    version: ros2-devel
$ vcs import src < turtlebot3.repos

注意:如果下载失败,通常是由于github.com的ip地址变化造成的,可以通过修改/etc/hosts来指定正确的ip地址。

2. 如果一切正常,然后开始编译
$ colcon build --symlink-install
现在开始排雷如下:

=>雷1:编译项目ld08_driver时,出现‘auto’ type specifier without trailing return type错误

--- stderr: ld08_driver

/opt/ros/humble/include/rosidl_runtime_cpp/rosidl_runtime_cpp/bounded_vector.hpp:477:3: error: ‘emplace_back’ function uses ‘auto’ type specifier without trailing return type
  477 |   auto

原因: ros2的代码使用了C++14特性,而编译选项却使用C++11

修改: 将编译选项修改为C++14就可以了

file: /home/frank/tb3_ws/src/utils/ld08_driver/CMakeLists.txt

SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

==>

SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")

注意:在该文件中确保如下设置

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

在编译,该问题得到解决!

新的问题来了

雷2:编译项目ld08_driver时,出现error: ‘variant’ in namespace ‘std’ does not name a template type错误

--- stderr: ld08_driver

error: ‘variant’ in namespace ‘std’ does not name a template type  786 |   using CallbackInfoVariant = std::variant<

note: ‘std::variant’ is only available from C++17 onwards

原因: 仍然是C++特性和编译选项不兼容造成的,C++文件使用了C++17特性

根据错误提示,“note: ‘std::variant’ is only available from C++17 onwards”才想到方法2。
修改:

1. CMAKE_CXX_STANDARD改为17

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

==>

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

2.同时CMAKE_CXX_FLAGS也改为17

SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")

==>

SET(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")

再编译,该问题得到很好的解决!!

Cheer!!!

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值