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
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章