1、vscode建立项目
选择一个文件夹,建立项目
2、建立子文件夹
src;include;build;CMakeLists.txt
3、写代码
4、写CMakeLists.txt
4.1、remember!!!要写debug模式编译
set(CMAKE_BUILD_TYPE "Debug")
4.2、进行代码编译优化 # debug 时 需要注释掉优化编译的命令
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")
5、获取代码提示。(与debug无关,没有c_cpp_properties.json貌似也可以debug)
ctrl+shift+p
输入
edit
选择c++ edit Configurations(json)
建立c_cpp_properties.json
在"includePath"中,
输入头文件的路径
6、code编译
用CMakeLists.txt方式编译
cmake ..
make
7、调试debug
ctrl+F5
run / start debugging
建立launch.json文件
修改launch.json文件:
program:路径设置为为cmake make 编译的可执行程序;
cwd:设置为${workspaceFolder}
注释掉"preLaunchTask",大概是因为不用预编译,已经用cmake make 编译完成了
args": [] 中写入程序需要的参数
{
// 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++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/sift",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
8、debug
然后使用ctrl+F5即可开始逐步的程序调试
快乐debug