VScode配置支持c++11和配置自动编译调试功能
- 1 在工程目录下新建.vscode目录
- 2 在.vscode目录下创建c_cpp_properties.json文件内容如下
- 2.1 添加c_cpp_properties.json后,关于c++11的相关类型或字段函数都可以正常识别了(如:atomic,auto,to_string等)
- 3 在.vscode目录下创建launch.json文件内容如下
- 4 在.vscode目录下创建tasks.json文件内容如下
- 5 在CMakeLists.txt添加如下内容,才能正常进行调试
- 6 验证,在main中打一个断点,然后F5调试运行
提示:以下是本篇文章正文内容,下面案例可供参考
1 在工程目录下新建.vscode目录
2 在.vscode目录下创建c_cpp_properties.json文件内容如下
{
"configurations": [
{
"name": "Ubuntu",
"includePath": ["${workspaceFolder}/**", "${workspaceFolder}/include/*"], // 需要更具自己的实际工程添加定义的头文件路径
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.17763.0",
//"compilerPath": "", // g++所在路径
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
2.1 添加c_cpp_properties.json后,关于c++11的相关类型或字段函数都可以正常识别了(如:atomic,auto,to_string等)
3 在.vscode目录下创建launch.json文件内容如下
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/SimulateSystemServer",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build", // 要执行的任务的label名
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
4 在.vscode目录下创建tasks.json文件内容如下
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"label": "cmake",
"type": "shell",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make", // windows: mingw32-make
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence", // 按列出顺序执行任务依赖项
"dependsOn":[
"cmake",
"make"
]
}
]
}
5 在CMakeLists.txt添加如下内容,才能正常进行调试
set(CMAKE_BUILD_TYPE Debug)
6 验证,在main中打一个断点,然后F5调试运行