简介
最官方的配置方案 https://code.visualstudio.com/docs/cpp/config-linux
有三个文件会生成
tasks.json (编译器构建设置)
launch.json (调试器设置)
c_cpp_properties.json (编译器路径和IntelliSense设置)
三个文件的配置命令
tasks.json
Terminal > Configure Default Build Task
选择 C/C++: g++ build active file
lauch.json
Run > Add Configuration... and then choose C++ (GDB/LLDB).
选择 Choose g++ build and debug active file.
c_cpp_properties.json
ctrl + shift + p 打开命令行 输入 c/c++
选择带有 ui 的那个
C/C++: Edit Configurations (UI)
复用配置文件
VS Code现在已配置为在Linux上使用gcc。该配置适用于当前工作空间。要重用配置,只需将JSON文件复制到.vscode新项目文件夹(工作区)中的文件夹中,然后根据需要更改源文件和可执行文件的名称。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
]
}
lauch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "调试",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/bin/${fileBasenameNoExtension}",
"args": ["-p", "3", "4", "5", "6"],
"stopAtEntry": false,
"cwd": "\\",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "clang - 生成和调试",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/bin/${fileBasenameNoExtension}", // 可以改成绝对路径
"args": ["-p", "3"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "clang build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》