【编译失败】MSYS2 ucrt64 win编译安装ros2 humble

文章目录

    • 参考资料
    • 为什么要这样安装,而不是直接使用官方编译好的二进制包
    • 依赖的安装
    • 【未成功】下载、编译ROS2 humble代码
    • 测试运行

参考资料

  • msys2安装与配置: 在windows上使用linux工具链g++和包管理工具pacman C++开发
  • Manjaro Linux安装ROS2 humble机器人系统:从开始到安装完成
  • ROS2/humble doc: building-from-source
  • ROS2/humble doc: Windows-Development-Setup
  • https://aur.archlinux.org/packages/ros2-humble

为什么要这样安装,而不是直接使用官方编译好的二进制包

官方依赖于VS2019,这个东西太大了,不想用,想和linux有一样的流程(比如ros2 c++项目的编译),就只好借助msys2了

依赖的安装

  • ros官方文档要 Python 3.8.3,我这里直接用msys2的最新Python 3.10了,可能导致pip安装包时出错,但下文有办法解决

  • opencv、qt6、qt5兼容层:通过pacman安装

  • 其他依赖 asio cunit eigen tinyxml-usestl tinyxml2 bullet
    安装过程

    pacman -S mingw-w64-ucrt-x86_64-asio mingw-w64-ucrt-x86_64-bullet mingw-w64-ucrt-x86_64-cunit mingw-w64-ucrt-x86_64-eigen3 mingw-w64-ucrt-x86_64-tinyxml2
    
    tinyxml-usestl.2.6.2 没有安装
    
    
  • 安装Python依赖

    • ros官方让这样安装这些包,但py3.10可能遇到错误,如果遇到错误,就用pacman -Ss 搜索该包的关键词,找到编译好的版本直接安装。这是官方的安装命令python -m pip install -U catkin_pkg cryptography empy importlib-metadata lark\==1.1.1 lxml matplotlib netifaces numpy opencv-python PyQt5 pillow psutil pycairo pydot pyparsing\==2.4.7 pyyaml rosdistro,我真正的安装过程如下:

      `pacman -S mingw-w64-ucrt-x86_64-python-cryptography`  # cryptography 直接用pip安装失败
      `pacman -S mingw-w64-ucrt-x86_64-python-lxml`
      `pacman -S mingw-w64-ucrt-x86_64-python-matplotlib`    # numpy,pillow,six什么的都会安装
      `pacman -S mingw-w64-ucrt-x86_64-python-netifaces`
      `pacman -S mingw-w64-ucrt-x86_64-python-opencv`
      `pacman -S mingw-w64-ucrt-x86_64-python-PyQt5 mingw-w64-ucrt-x86_64-pyqt5-sip # mingw-w64-ucrt-x86_64-python-sip4`
      `pacman -S mingw-w64-ucrt-x86_64-python-psutil mingw-w64-ucrt-x86_64-python-cairo mingw-w64-ucrt-x86_64-python-dotenv mingw-w64-ucrt-x86_64-python-yaml`
      
      `python -m pip install -U catkin_pkg empy importlib-metadata lark==1.1.1  rosdistro`
      
  • 安装qt5: pacman -S mingw-w64-ucrt-x86_64-qt5-base

  • 安装Graphviz:pacman -S mingw-w64-ucrt-x86_64-graphviz

  • 安装额外依赖(ros源码编译所需的)

    • pacman -S mingw-w64-ucrt-x86_64-cppcheck

    • python: 官方的安装命令pip install -U colcon-common-extensions coverage flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mock mypy==0.931 pep8 pydocstyle pytest pytest-mock vcstool,我实际的安装过程:

      pacman -S mingw-w64-ucrt-x86_64-python-pywin32
      pip install -U colcon-common-extensions  flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mock mypy==0.931 pep8 pydocstyle pytest pytest-mock vcstool
      

【未成功】下载、编译ROS2 humble代码

  • 下载

    • mkdir -p /e/ros2_humble/src && cd /e/ros2_humble
    • clone github仓库
      • 方法一(如果你的网络ok):vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src
      • 方法二(使用镜像)
        • 把ros2.repos文本文件保存到本地:wget https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos

        • 把里面每个github.com修改为镜像地址,然后写python脚本手动clone

          import os
          from time import sleep
          
          def main():
              repos = "./ros2.repos"      # 要clone的仓库信息文件在这里
              
              with open(repos, 'r') as f:
                  os.chdir("./src")       # 要clone到这里
                  already_repos = os.listdir("./")
                  print(already_repos)
          
                  lines = f.readlines()
                  for i, line in enumerate(lines):
                      if "version: " in line:
                          version = line.split("version: ")[1].strip()
                          
                          line_url = lines[i-1]
                          url = line_url.split("url: ")[1].strip()
                          url = git_mirror(url)
          
                          line_name = lines[i-3]
                          name = line_name.rsplit("/", 1)[1].replace(":", "").strip()
                          if name in already_repos:  # 跳过已clone的仓库 so that 出错了可以重新运行开始
                              print(name)
                              continue
          
                          print(f"try to clone - line: {i-3+1}, name: {name}")
                          ret = os.system(f"git clone {url} -b {version}")
                          if (ret != 0):  # 出错了停止
                              exit(ret)
          
                          sleep(5)       # 等待,防止下一个clone出错
                          print("finish clone\n")
          
          # 尝试不同的镜像
          def git_mirror(url):
              return "https://ghproxy.com/" + url
              # return "https://github.moeyy.xyz/" + url
              # return url.replace("github", "kgithub")
              # return url.replace("github.com", "hub.fgit.ml")
              # return url.replace("github.com", "hub.fgit.gq")
              # return url.replace("github.com", "gitclone.com/github")
          
          if __name__ == "__main__":
              main()
          
  • 编译: colcon build --merge-install, 运行此命令时你应位于src的同级目录(不是在src里面)

    • 没有编译成功。。。。。。colcon编译ros组件的时候,很多还是默认平台windows,就需要vs2019环境。强行设置为linux, unix会报错缺少函数定义。

测试运行

https://docs.ros.org/en/humble/Installation/Alternatives/Windows-Development-Setup.html#environment-setup

你可能感兴趣的:(ros,humble,msys2,opencv,g++,win)