在gcc/g++能编译运行c++的情况下,使用cmake编译只需要修改以下两个文件。
launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "g++-9 - 生成和调试活动文件","type": "cppdbg","request": "launch",//attach为附加//"program":"${fileDirname}/${fileBasenameNoExtension}","program": "cmake.launchTargetPath","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true}],//"preLaunchTask": "C/C++: g++-9 生成活动文件","miDebuggerPath": "/usr/bin/gdb"}]
}
tasks.json
{"tasks": [{"type": "cppbuild","label": "make build",//编译的项目名,build//"label": "C/C++: g++-9 生成活动文件","command":"cd ./build ;cmake ../ ; make",//使用cmake编译的3组命令//"command": "/usr/bin/g++-9","args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${workspaceFolder}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "调试器生成的任务。"}],"version": "2.0.0"
}