VScode配置C环境和导入keil工程


目录

  • VScode配置C环境和导入keil工程
  • 一、安装VScode
  • 二、VScode界面汉化
  • 三、电脑配置C环境
  • 四、VScode配置C环境
  • 五、VScode导入keil工程


一、安装VScode

打开下载好的安装包:

vscode 导入android studio 工程 vscode导入c工程_arm

vscode 导入android studio 工程 vscode导入c工程_arm_02

vscode 导入android studio 工程 vscode导入c工程_stm32_03

vscode 导入android studio 工程 vscode导入c工程_arm_04

vscode 导入android studio 工程 vscode导入c工程_stm32_05

vscode 导入android studio 工程 vscode导入c工程_arm_06

二、VScode界面汉化

vscode 导入android studio 工程 vscode导入c工程_单片机_07

vscode 导入android studio 工程 vscode导入c工程_单片机_08

此时重启之后就是汉化之后的界面了

三、电脑配置C环境

1.解压此文件夹到一个文件夹(路径不要带有中文)

vscode 导入android studio 工程 vscode导入c工程_c语言_09

2.打开此文件

vscode 导入android studio 工程 vscode导入c工程_vscode_10

3.找到文件中的bin文件,复制地址

vscode 导入android studio 工程 vscode导入c工程_vscode_11

4.打开环境变量

vscode 导入android studio 工程 vscode导入c工程_vscode_12

5.打开path

vscode 导入android studio 工程 vscode导入c工程_vscode_13

6.点击‘新建’,将刚刚复制的地址粘贴进去,点击确定

vscode 导入android studio 工程 vscode导入c工程_stm32_14

7.打开cmd,在命令行窗口输入gcc -v -E -x c++ -,出现以下内容表示环境配置成功

vscode 导入android studio 工程 vscode导入c工程_stm32_15

四、VScode配置C环境

1.安装C/C++

vscode 导入android studio 工程 vscode导入c工程_c语言_16

2.在桌面创建一个文件夹,用来存放C文件

vscode 导入android studio 工程 vscode导入c工程_arm_17

3.在文件夹中创建一个.c文件和一个.vscode的文件夹

vscode 导入android studio 工程 vscode导入c工程_stm32_18

4.在.vscode文件夹中创建三个.json文件

vscode 导入android studio 工程 vscode导入c工程_stm32_19

c_cpp_properties.json文件内容:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "D:/VSCODE/EXE/mingw64/include/**",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "D:/VSCODE/EXE/mingw64/include/**",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                    "D:/VSCODE/EXE/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
                ]
            }
        }
    ],
    "version": 4
}

launch.json文件内容:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "preLaunchTask": "echo",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole":true
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\VSCODE\\EXE\\bin\\gdb.exe",// 自己电脑的gdb
            "preLaunchTask": "echo",//这里和task.json的label相对应
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
 
        }
    ]
}

tasks.json文件内容:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "${file}", 
                "-o", 
                "${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"//解决中文乱码
            ]
        }
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared", 
        "showReuseMessage": true,
        "clear": false
    }
}

5.将c_cpp_properties.json中的路径改成自己的实际路径

vscode 导入android studio 工程 vscode导入c工程_stm32_20

6.将launch.json中的路径也改成自己的实际路径

vscode 导入android studio 工程 vscode导入c工程_arm_21

7.在VScode中打开创建的文件夹

vscode 导入android studio 工程 vscode导入c工程_vscode_22

8.写一个简单的"Hello,World!"代码

vscode 导入android studio 工程 vscode导入c工程_stm32_23

9.运行代码(F5)检查C环境是否配置成功,打印出"Hello,World!"即成功!(可以将.vscode中的三个文件保存起来,以后创建.c文件时直接复制即可)

vscode 导入android studio 工程 vscode导入c工程_单片机_24

五、VScode导入keil工程

VScode中不仅能打开keil工程,还能够进行修改和编译

1.安装Embedded IDE插件

vscode 导入android studio 工程 vscode导入c工程_vscode_25

2.点击设置工具链

vscode 导入android studio 工程 vscode导入c工程_stm32_26

3.选择’Keil MDK’

vscode 导入android studio 工程 vscode导入c工程_arm_27

4.找到keil安装路径,选择’TOOLS.INI’文件

vscode 导入android studio 工程 vscode导入c工程_单片机_28

5.导入keil工程

vscode 导入android studio 工程 vscode导入c工程_单片机_29

6.选择MDK

vscode 导入android studio 工程 vscode导入c工程_单片机_30

7.导入成功

vscode 导入android studio 工程 vscode导入c工程_vscode_31

8.编译工程

vscode 导入android studio 工程 vscode导入c工程_vscode_32

9.在烧录配置处进行设置后,可以直接使用JLink将程序烧录到开发板

vscode 导入android studio 工程 vscode导入c工程_单片机_33

vscode 导入android studio 工程 vscode导入c工程_c语言_34

到此,VScode配置C环境和导入keil工程完毕!


2022.9.9更新:VScode安装包及C/C++环境配置文件下载