vscode

c++配置

安装依赖

sudo apt install build-essential gdb

安装扩展

打开 extensions
安装 c/c++

创建cmake项目

  • ctrl + shift + P
  • 填入创建的可执行程序名称:比如demo
  • 选择创建c++
  • 选择可执行程序: exec

    配置调试

  • 选中main.cpp
  • 菜单栏,选择run,选择debug;或者按F5
  • 选择c++/g++ activate debug….

    远程c++,rust项目配置

    laugh.json
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Debug condition_se",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/build/condition_se",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}",
    "environment": [
    {
    "name": "LD_LIBRARY_PATH",
    "value": "${workspaceFolder}/third_party/tokenizers-cpp/release/x64/lib"
    }
    ],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
    {
    "description": "Enable pretty-printing for gdb",
    "text": "-enable-pretty-printing",
    "ignoreFailures": true
    }
    ],
    "preLaunchTask": "CMake: build",
    "miDebuggerPath": "/usr/bin/gdb"
    }
    ]
    }

program为编译出的可执行文件路径,解决找不到可执行文件的问题
environment为环境变量,解决找不到库的问题

task.json

{
"version": "2.0.0",
"tasks": [
{
"label": "CMake: configure",
"type": "shell",
"command": "cmake",
"args": [
"-S",
"${workspaceFolder}",
"-B",
"${workspaceFolder}/build"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task by CMake Tools extension"
},
{
"label": "CMake: build",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"${workspaceFolder}/build"
],
"group": "build",
"problemMatcher": ["$gcc"],
"dependsOn": "CMake: configure",
"detail": "Generated task by CMake Tools extension"
}
]
}

------ 本文结束 🎉🎉 谢谢观看 ------
0%