搭建windows平台arm交叉编译环境

VsCode + CMake + Linaro配置交叉编译环境

采用Linaro公司的交叉编译工具。

下载VsCode和CMake

参见这里,不再赘述了。

下载Linaro

网址:https://www.linaro.org/downloads/

根据arm 型号和目标系统版本选择对应的交叉编译工具集: 如arm v7 32bit 下载:

gcc-linaro-7.5.0-2019.12-i686-mingw32_arm-linux-gnueabihf.tar.xz

下载解压到任意目录(%LINARO_PATH%)

配置Linaro的CMake脚本

在解压目录新建cmake文件夹,并新建名为toolchain.cmake的文本文件, 文件内容如下:

### toolchain.cmake ###
# this is required
SET(CMAKE_SYSTEM_NAME Linux)

# specify the cross compiler
SET(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc.exe")
SET(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++.exe")
SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE FILEPATH "C Compiler")
SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE FILEPATH "CXX Compiler")

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH "$ENV{CMT_MINGW_PATH}/../")

# search for programs in the build host directories (not necessary)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

下载拷贝一个ming32-make.exe到%LINARO_PATH%\bin文件夹中

配置 VsCode的CMake插件

  1. 打开cmake-tools-kits.json文件(C:\Users\<用户名>\AppData\Local\CMakeTools\cmake-tools-kits.json)

  2. 添加以下内容:

  {
    "name": "arm_corss_compiler",
    "toolchainFile": "%LINARO_PATH%/cmake/toolchain.cmake",
    "preferredGenerator": {
      "name": "MinGW Makefiles"
    },
    "environmentVariables": {
      "CMT_MINGW_PATH": "%LINARO_PATH%/bin"
    }
  }

完成

打开VsCode,新建一个CMake工程,然后测试吧。

blogroll

social