准备条件:
已安装编译器 mingw64 同时 把 D:\mingw64\bin加入到环境变量中
在 CMD 中 通过 gcc -V 可查询到版本 gcc version 8.1.0
在.vscode 中新建
c_cpp_properties.json C/CPP 配置参数
此文件亦新建方式可通过 shift + ctrl + p
输入C/Cpp: Edit configurations 可视化配置一些信息
{
"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",
"cStandard": "c99",
"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"
]
},
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
configurations :一组配置对象,向智能感知引擎提供项目和首选项信息
name:标识配置文件,一般用内核的名字即可 '"Win32"
includepath:指明头文件包含路径(标准库等) 很重要
cStandard:C99标准
defines:用于智能感知引擎解析文件时使用预处理程序定义的列表,所以没必要在编译时候加的宏定义写在尺寸,用browse即可
intelliSenseMode:智能感知模式 msvc-x64.gcc-x64和clang-x64 此处 msvc-x64
browse:通过该字段下的path下的所有的宏定义,并把缺少的宏定义补全,让Define/Declartion无障碍通过 (很重要 )
browse 有3个字段 :
path:看上面
limitSymbolsToIncludedHeaders:当不能 代码补全提示时候改成false 试试
databaseFilename:无用
lauch.json:调试器启动参数
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/test.exe",//这里填cmake 生产的exe
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "make",//这里和task.json的label相对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
name:名称
type: 类型 此处智能是 cppdbg
request:请求配置类型,可以位 launch(启动) 或者 attach(附加)
program:将要执行的程序路径
args[]:参数一为空
stopAtEntry:设置为true 将停止 main 入口出
cmd:当前工作目录
environment:一般为空
externalConsole: true 调试时候是否显示控制台
MIMode:gdb 指定连接的调试器
preLaunchTask : "make" 调试之前开始执行的任务,一般为编译程序 这里和task.json的label相对应
miDebuggerPath: D:\\mingw64\\bin\\gdb.exe 调试器路径
preLaunchTask: "make",//调试开始之前执行的任务一般是编译程序这里和task.json的label相对应
setupCommands:用处位置 模板如此
tasks.json:任务参数
这个文件是定义调试开始 前要执行的任务,正常就是编译程序,定义了用于编译程序的编译器 按下F5 根据配置文件运行
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cmake",
"options": {
"cwd": "${workspaceFolder}/build" //切换到build 下,重要!
},
"type": "shell",
"command": "cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug .. ",
},
{
"label": "make",
"options": {
"cwd": "${workspaceFolder}/build" //切换到build 下,重要!
},
"type": "shell",
"command": "make -j8", //-j n 电脑几核就可以写几,加快编译速度
"dependsOn":[ "cmake" ], //非常重要! make 的执行依赖 Cmake 执行完毕,不然呵呵
}
]
}
首先通过 cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug ..
在build目录下 生成MakeFile等文件
然后通过 make 命令 去编译
make -j8 多线程编译
此处的
make 标签 和 lauch.json 中的preLaunchTask 对应
调试的时候也会调用这个任务