mac下的vscode配置编译环境

基础开发环境

创建Dockerfile文件,内容如下:

FROM ubuntu:20.04

RUN apt update & apt install make gcc cmake git ninja-build -y
CMD [ "sleep", "infinity" ]

创建docker-compose.yml文件,内容如下:

version: '3.4'

services:
  aipiopenkits:
    volumes:
      - /Users/xxx/AiPi/AiPi-Open-Kits:/workspace
    devices:
      - /dev/ttyUSB0:/dev/ttyS0
    platform: linux/x86_64
    image: ubuntu:my
    build:
      context: .
      dockerfile: ./Dockerfile

进入容器后,下载需要的包

apt update & apt install vim make -y

为了避免第二次启动时,把原来已经创建的容器内的文件删掉。所以之后可以去掉docker-compose.yml中的build部分,已避免第二次编译docker镜像。

vim ~/.bashrc

最后加上 export PATH=$PATH:/workspace/aithinker_Ai-M6X_SDK/toolchain/bin
这样的话,就不用每次都export了,直接就可以编译

代码的友好阅读

vscode自定义编译工具链的路径
在.vscode目录下创建

/workspace/aithinker_Ai-M6X_SDK/toolchain/bin/riscv64-unknown-elf-gcc

vscode解决头文件无法跳转的问题

${workspaceFolder}/**
/workspace/aithinker_Ai-M6X_SDK/toolchain/riscv64-unknown-elf/**/**
/workspace/aithinker_Ai-M6X_SDK/components/**/**
/workspace/aithinker_Ai-M6X_SDK/drivers/**/**

以上2步,可以直接操作文件来实现 .vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/workspace/aithinker_Ai-M6X_SDK/toolchain/riscv64-unknown-elf/**/**",
                "/workspace/aithinker_Ai-M6X_SDK/components/**/**",
                "/workspace/aithinker_Ai-M6X_SDK/drivers/**/**",
                "/workspace/aithinker_Ai-M6X_SDK/bsp/common/**/**"
            ],
            "defines": [],
            "cStandard": "c17",
            "cppStandard": "c++98",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerPath": "/workspace/aithinker_Ai-M6X_SDK/toolchain/bin/riscv64-unknown-elf-gcc"
        }
    ],
    "version": 4
}

同时为解决vscode默认编译环境的问题,需改.vscode/settings.json中的

{
    "C_Cpp.default.compilerPath": "/workspace/aithinker_Ai-M6X_SDK/toolchain/bin/riscv64-unknown-elf-gcc",
} 

MAC下无法编译,验证完毕

编译工具链步骤
参考文档 https://github.com/p4ddy1/pine_ox64/blob/main/build_toolchain_macos.md

依赖

  • Homebrew (https://brew.sh)
  • XCode
  • Git

资源

brew install --build-from-source gawk gnu-sed gmp mpfr libmpc isl zlib expat

zlib会下载失败,想办法科学上网,一道无形的阻力,压制了无数大佬的血统

brew install --build-from-source coreutils

brew install --build-from-source texinfo

brew tap riscv-software-src/riscv
brew install riscv-tools

$ git clone --recurse-submodules https://github.com/T-head-Semi/xuantie-gnu-toolchain.git
$ git clone https://github.com/bouffalolab/bl_mcu_sdk.git

你可能感兴趣的:(macos,vscode,ide,单片机)