前期准备
- 下载安装vscode
- 下载mingw64,网址
https://sourceforge.net/projects/mingw-w64/files/
将下载好的mingw64解压到指定的目录,这个是我的路径D:\mingw64 解压好之后,还需要配置环境变量 将目录D:\mingw64\bin追加到环境变量path里
在命令行里输入gcc -v
,输出以下版本信息则表示minGW配置OK
- 安装C/C++插件
- 建立配置文件
建立一个文件夹,命名为VS-Code-C
目录下创建.vscode目录(注意有一个点)
在.vscode目录下创建一下三个配置文件
c_cpp_properties.json
launch.json
tasks.json
配置文件里面的内容分别对用如下:
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"D:/mingw64/include/**",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/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:/mingw64/include/**",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/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": "(gdb)c_launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
//替换电脑中的路径
"miDebuggerPath": "D:/mingw64/bin/gdb.exe",
"MIMode": "gdb",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"internalConsoleOptions": "openOnFirstSessionStart",
"externalConsole": true,
"preLaunchTask": "gcc"
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "gcc",
"args": ["-Wall", "-g", "${file}", "-o", "${fileBasenameNoExtension}.exe"],
"echoCommand": true,
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
测试配置结果
#include<stdio.h>
int main(){
printf("xxg123xsg\n");
system("pause");
return 0;
}