打开wsl,进入文件夹,运行以下命令:
code .
在 CMakeLists.txt 中设置
set ( CMAKE_BUILD_TYPE "Debug" )
配置 lauch.json,该文件用于执行编译好的文件(该文件位于 .vscode 中)
"version" : "0.2.0" ,"configurations" : [{"name" : "g++ - 生成和调试活动文件" ,"type" : "cppdbg" ,"request" : "launch" ,//目标执行文件"program" : "${workspaceFolder}/build/hello" ,"args" : [],"stopAtEntry" : false ,"cwd" : "${workspaceFolder}" ,"environment" : [],"externalConsole" : false ,"MIMode" : "gdb" ,"setupCommands" : [{"description" : "为 gdb 启用整齐打印" ,"text" : "-enable-pretty-printing" ,"ignoreFailures" : true}],"preLaunchTask" : "make" ,"miDebuggerPath" : "/usr/bin/gdb"}]
配置 tasks.json,用于编译,(该文件位于 .vscode 中)
{"tasks" : [{"label" : "mkdir" ,"type" : "shell" ,"command" : "mkdir" ,"args" : [ "-p" , "build" ],"options" : {"cwd" : "${workspaceFolder}"}},{"label" : "cmake" ,"type" : "shell" ,"command" : "cmake" ,"args" : [ ".." ],"options" : {"cwd" : "${workspaceFolder}/build"},"dependsOn" :[ "mkdir" ]},{"label" : "make" , //需要和 lauch.json 中的 "preLaunchTask" 相同"type" : "shell" ,"command" : "make" ,"args" : [],"options" : {"cwd" : "${workspaceFolder}/build"},"dependsOn" :[ "cmake" ] //执行当前命令前先执行 label 为 cmake 的命令}],"version" : "2.0.0"}
打上断点,点击运行,就可以开始调试啦
来源:oschina
链接:https://my.oschina.net/u/4277806/blog/4306400