看了一些大佬的vscode c/c++环境配置攻略,结合自己的理解,在这里我将我的.json配置分享给大家,供大家参考,希望能在您学习路上带来一些帮助。我用的编译器是WinGW。
话不多说,开始各个文件的配置及代码(直接复制即可,部分地址需要修改,已在备注内标出)。.json文件没有按先后顺序排序,请根据对应的文件修改。
首先是c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [ //这里是编译器内的头文件地址,请根据编译器的安装目录填写
"${workspaceFolder}/**",
"E:\\Compiler\\WinGW\\mingw64\\include\\",
"E:\\Compiler\\WinGW\\mingw64\\include\\gdb\\",
"E:\\Compiler\\WinGW\\mingw64\\include\\libiberty\\",
"E:/Compiler/WinGW/mingw64/lib/",
"E:\\Compiler\\WinGW\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\32/",
"E:/Compiler/WinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/*",
"E:/Compiler/WinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/*",
"E:/Compiler/WinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/ssp/*"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "msvc-x64",
"compilerPath":"E:/Compiler/WinGW/mingw64/bin/gcc.exe", //编译器所在的地址,根据自己编译器所在的位置填写。
"browse": {
"path": [ //这里任然是编译器内的头文件地址
"${workspaceRoot}",
"${MINGW_HOME}\\include\\c++\\7.1.0",
"${MINGW_HOME}\\include\\c++\\7.1.0\\x86_64-w64-mingw32",
"${MINGW_HOME}\\include\\c++\\7.1.0\\backward",
"${MINGW_HOME}\\lib\\gcc\\x86_64-w64-mingw32\\7.1.0\\include",
"${MINGW_HOME}\\include",
"${MINGW_HOME}\\x86_64-w64-mingw32\\include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
接下来是launch.josn的配置
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示,可以自行更改
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
"miDebuggerPath": "E:/Compiler/WinGW/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
接着是tasks.json文件的配置
{
"version": "2.0.0",
"command": "g++",
"args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
这是本人第一篇博客,不当之处还请大家指正,希望对您在vscode配置c的环境中有帮助,谢谢观看。
2018/10/17