插件
这几个是必须的
配置
cmake
创建一个CMakeLists.txt,这是cmake的配置文件
c/cpp插件(高亮)
ctrl + shift + p打开vscode的命令窗口
选择 c/c++编辑配置(UI)
手动在c_cpp_properties.json添加"configurationProvider": "vector-of-bool.cmake-tools"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/clang", "cStandard": "c17", "cppStandard": "c++23", "intelliSenseMode": "linux-clang-x64", "configurationProvider": "vector-of-bool.cmake-tools" } ], "version": 4 }
|
在linux系统下保存完长这样,其他系统按上面的步骤不用管
调试
选中左边主侧栏的”运行和调试”,点击创建launch.json文件
lldb的话应该长这样
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "Debug", "program": "${workspaceFolder}/<executable file>", "args": [], "cwd": "${workspaceFolder}" } ] }
|
gdb的话长这样(默认配置这么麻烦,现在知道该选谁了吧~~~)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| { "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "输入程序名称,例如 ${workspaceFolder}/a.out", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] }
|
然后把”program”项改成"${command:cmake.launchTargetPath}"
,gdb和lldb都一样
如果最底下没有cmake信息的话试试重启vscode或者重装cmake插件
点击底下的no kit selected,为cmake选一个编译工具
现在基本上配置差不多了
测试
配置好了试试能不能用,随便写一个hello world(并不是
按f5开始调试