Windows源码编译ros2(rolling版本)

参考步骤:

https://docs.ros.org/en/rolling/Installation/Alternatives/Windows-Development-Setup.html#get-ros-2-code

1)新建src目录:

C:\ros\rolling>vcs import --input https://gitcode.net/rose3/rose3/-/raw/master/ros2.rolling.repos src

2)run within a Visual Studio Command Prompt

c:\ros\rolling>colcon build --merge-install --cmake-args  -G "Visual Studio 17 2022" -A x64

问题1:

--- stderr: fastcdr
CMake Error at CMakeLists.txt:84 (project):
  No CMAKE_CXX_COMPILER could be found.

出错的cmakelists.txe是:
project(fastcdr VERSION "${LIB_VERSION_STR}" LANGUAGES CXX)

是cmake和Windows SDK版本的问题,可能是安装了多个SDK(见https://blog.csdn.net/qq_39482438/article/details/81013100 第3种情况),把所有sdk删除再重新安装最新的SDK后问题解决)

问题2:

1 package failed: uncrustify_vendor

打印出错信息:--event-handlers console_direct+

colcon build --merge-install --cmake-args  -G "Visual Studio 17 2022" -A x64 --event-handlers console_direct+ --packages-select uncrustify_vendor

[Processing: uncrustify_vendor]
  === .\uncrustify_vendor (git) ===
  fatal: unable to access 'https://github.com/uncrustify/uncrustify.git/': Failed to connect to github.com port 443 after 21073 ms: Couldn't connect to server

ros2中,xxx_vendor的子工程,都是xxx的一个编译封装,cmake下载github失败就把下载地址改一下: https://gitcode.net/rose3/uncrustify_vendor/-/merge_requests/1

问题3:

 1 package failed: pybind11_vendor

Performing download step for 'pybind11_vendor'
  === .\pybind11_vendor (git) ===
  Could not determine ref type of version: fatal: unable to access 'https://github.com/pybind/pybind11.git/': Failed to connect to github.com port 443 after 21061 ms

 如果要查看具体编译错误,可以使用一下参数: --event-handlers console_direct+

例如:

colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo --packages-up-to pybind11_vendor

问题4:

Could NOT find Bullet (missing: BULLET_DYNAMICS_LIBRARY
  BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY BULLET_SOFTBODY_LIBRARY
  BULLET_INCLUDE_DIR)

源码编译安装:https://gitcode.net/rose3/bullet3.git

修正了原master branch中的cmake错误。

cmake编译选项:-DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON -DINSTALL_LIBS=ON

### 如何在 Windows 系统中从源码编译并安装 ROS2 要在 Windows 上从源码编译并安装 ROS2,可以按照以下方式操作: #### 准备工作 确保开发环境已经满足基本需求。这包括安装 Visual Studio 和 Python 开发工具链以及必要的依赖项。 1. **设置开发者环境** 需要安装最新版的 Visual Studio 并启用 C++ 支持功能包[^2]。此外还需要安装 Chocolatey 或其他类似的包管理器来简化依赖项的安装过程。 2. **安装依赖库** 使用 PowerShell 执行命令以获取所需的依赖关系: ```powershell choco install python git cmake vc-redist-all vcredist2019 vcredist2017 ninja ``` #### 获取 ROS2 源码 接下来是从官方仓库拉取最新的 ROS2 源代码文件到本地计算机上。 1. 创建一个新的目录用于存储 ROS2 的源代码,并进入该路径。 ```cmd mkdir \ros2_ws\src cd \ros2_ws\src ``` 2. 利用 `vcs` 工具导入指定分支下的所有必要资源。 ```cmd pip install vcstool curl -sk https://raw.githubusercontent.com/ros2/ros2/rolling/ros2.repos > ros2.repos vcs import --input ros2.repos ``` #### 编译 ROS2 源码 完成上述步骤之后就可以开始实际的构建流程了。 1. 初始化 colcon 构建系统所需的工作区结构。 ```cmd call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" set COLCON_PREFIX_PATH= colcon build --merge-install --cmake-generator Ninja --event-handler console_cohesion+ ``` 2. 设置环境变量以便能够正常使用新安装好的 ROS2 功能集。 将下面这段脚本加入用户的 PATH 中或者每次打开终端前手动执行它。 ```batch @echo off :: Set up the environment variables to point at our workspace. set ROS_LOCAL_WS=C:\path\to\your\workspace set PYTHONPATH=%ROS_LOCAL_WS%\install\Lib\site-packages;%PYTHONPATH% set PATH=%ROS_LOCAL_WS%\install\bin;%PATH% ``` #### 测试安装成果 最后验证整个安装是否成功无误可以通过运行简单的 demo 来确认一切正常运作。 ```bash colcon test ``` 如果以上每一步都顺利完成,则表明已经在 Windows 下完成了基于源码ROS2 安装[^4]。 ---
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值