VSCode C++编译环境配置

VSCode C++编译环境配置


需要下载的文件:

Mingw64编译器

相当于Windows版本的一个GCC实现,是整体配置的后端。

LLVM,Clang,LLDB调试器

LLVM
LLVM是编译前端,负责make和组织代码,调试工作。

LLVM

LLVM项目是模块化和可重用的编译器及工具链技术的集合。尽管名称如此,LLVM与传统虚拟机关系不大。名称“ LLVM”本身不是缩写。它是项目的全名。

Clang

Clang是“ LLVM本机” C / C ++ / Objective-C编译器,旨在提供惊人的快速编译,极其有用的错误和警告消息,并为构建出色的源代码级工具提供平台。该Clang Static Analyzerclang-tidy,可在你的代码自动发现错误,而且是那种可以使用Clang前端的库来解析C / C ++代码生成工具的很好的例子。

LLDB

LLDB项目构建于LLVM和Clang提供的库文件支持上,是一个良好的native语言调试器。它使用Clang ASTs和语法识别器,LLVM,JIT,LLVM反编译器等组件,提供一种“十分有效”的调试体验,相比于GDB,它同时也有极高的速度和内存效率。

The LLDB project builds on libraries provided by LLVM and Clang to provide a great native debugger. It uses the Clang ASTs and expression parser, LLVM JIT, LLVM disassembler, etc so that it provides an experience that “just works”. It is also blazing fast and much more memory efficient than GDB at loading symbols.

LLDB是LLVM的一部分,本身是一个调试器。

配置 VSCode

常用的 VSCode 变量名

  • ${workspaceFolder} - the path of the folder opened in VS Code
  • ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
  • ${file} - the current opened file
  • ${relativeFile} - the current opened file relative to workspaceFolder
  • ${relativeFileDirname} - the current opened file’s dirname relative to workspaceFolder
  • ${fileBasename} - the current opened file’s basename
  • ${fileBasenameNoExtension} - the current opened file’s basename with no file extension
  • ${fileDirname} - the current opened file’s dirname
  • ${fileExtname} - the current opened file’s extension
  • ${cwd} - the task runner’s current working directory on startup
  • ${lineNumber} - the current selected line number in the active file
  • ${selectedText} - the current selected text in the active file
  • ${execPath} - the path to the running VS Code executable
  • ${defaultBuildTask} - the name of the default build task

task.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [{
            "label": "Compile",
            "type": "shell",
            "command": "clang++",
            "args": [
                "-g",
                "-o",
                "${workspaceFolder}\\${relativeFileDirname}\\build\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "absolute",
                    //"${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }

            }
        },
        {
            "label": "Run",
            "type": "shell",
            "command": "${workspaceFolder}\\${relativeFileDirname}\\build\\${fileBasenameNoExtension}.exe",
            "args": [],
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

launch.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": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\${relativeFileDirname}\\build\\${fileBasenameNoExtension}.exe",
            "args": [],
            "preLaunchTask": "Compile",
            //"type": "shell"
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Software\\LLVM\\bin\\gdb.exe",
            "setupCommands": [{
                "description": "为 gdb 启用整齐打印",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }]
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
发布了23 篇原创文章 · 获赞 5 · 访问量 1842

猜你喜欢

转载自blog.csdn.net/QQ275176629/article/details/104251966