文章目录
1 MinGW 与 CMake下载
- 网盘地址
https://pan.baidu.com/s/1UvzMpnxo-L_nSbiCXYLjVw
- 提取码
vs41
2 配置环境变量
2.1 测试CMake的安装
2.2 在VSCode中使用
- 配置环境变量后,在VSCode中,可以run code
配置插件
3 安装C/C++扩展
-
C/C++
-
CMake
-
CMake Tool
4 Test
4.1 编写C++文件
- 编写好,点击
run code
即可运行
4.2 使用cmake进行调试
- CMake编写的文件
- 编写
CMakeLists.txt
文件, 文件名正确, 没有中文
- 生成
build
文件夹
Ctrl
+ shift
+ p
cmake Configure
- 配置
launch.json
文件,
4.3 Json文件编写
1 launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
// "miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- tsaks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\MinGW\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\MinGW\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}
5 总结
- 使用debug功能的时候,CMake创建的文件,不能含有中文路径,否则文件不能找到