参考网址:
(137条消息) Ubuntu下VsCode和CMake联合调试C++工程_还没想好~的博客-CSDN博客
(137条消息) Ubuntu下VSCode+Cmake配置开发环境_Stone_OverLooking的博客-CSDN博客
步骤
安装gdb
cmake配置
1 2 3 4 5
| # 设置编译模式 set( CMAKE_BUILD_TYPE "Debug" ) set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb") set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") add_definitions(-std=c++11)
|
编译
1 2 3
| mkdir build cd build cmake .. && make -j8
|
c_cpp_properties.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| { "configurations": [ { "name": "Linux", "includePath": [ "/usr/include", "/usr/local/include", "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64", "compileCommands": "${workspaceFolder}/build/compile_commands.json" } ], "version": 4 }
|
launch.json
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
| { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/Groot", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "make build" } ] }
|
tasks.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "make build", "type": "shell", "command": "cd ./build ;cmake ../ ;make -8", "group": { "kind": "build", "isDefault": true } }, { "label": "clean", "type": "shell", "command": "make clean" } ] }
|