-
把mingw64添加环境变量,mingw-64\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64\bin
-
ctrl+r 打开cmd 输入 gcc-v 回车
-
C:\Users\chade>md cplusplus-project C:\Users\chade>cd cplusplus-project C:\Users\chade\cplusplus-project>code .
-
这时vscode应该已经打开,创建hello.cpp文件,确保打开的是当前文件,点击运行,点击打开配置,选择 gdb c++ 自动生成两个配置文件
tasks.json
launch.json
tasks.json
编译任务配置launch.json
调试配置c_cpp_properties.json
c/c++ 编译版本配置
https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
5.创建helloc.c文件,点击菜单上的终端,再点击配置默认生成项目,自动打开tasks.json
,就会多了gcc C/C++: gcc.exe build active file
更多配置可,ctrl + shift + b 输入c/c++
以下是自动生成的文件
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe"
}
],
"version": "2.0.0"
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\SoftwareDevelopmentEnvironment\\CPlusPlusSoftwareEnvironment\\mingw-64\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}