系统相关
首页 > 系统相关> > LLVM+clang+vs code+ubuntu

LLVM+clang+vs code+ubuntu

作者:互联网

首先这篇文章参考了以下两位的分享:

https://rob-blackbourn.github.io/blog/vscode/clang/llvm/ubuntu/20.04/2021/07/04/howto-llvm-vscode-ubuntu.html

在VS Code中使用Clang作为你的C++编译器 - 简书 (jianshu.com)

本文章主要是分享自己在Ubuntu的VS Code上配置LLVM和Clang的小总结

按下面配置好基本不会有什么问题,有一个需要注意的是(因为我也是复制的,所以不太懂)需要在程序最后一行设置一个断点才可以正常运行

需要安装的包有:

sudo apt install llvm clang clangd liblldb-dev

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": "clang++ - Build and debug active file",
            "type": "lldb",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++ build active file",
            "miDebuggerPath": "/usr/lib/llvm-10/bin" //这里要找到自己的llvm路径
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "C/C++: clang++ build active file", // 任务名称,与launch.json的preLaunchTask相对应
            "command": "clang++", // 如果用MinGW,编译C用gcc,编译c++用g++
            "args": [
                "${file}",
                "-o", // 指定输出文件名,不加该参数则默认输出a.exe 
                "${fileDirname}/${fileBasenameNoExtension}",
                "-g", // 生成和调试有关的信息
                "-Wall", // 开启额外警告
                "-static-libgcc", // 静态链接 
                "-fcolor-diagnostics",
                //"--target=x86_64-w64-mingw", // 默认target为msvc,不加这一条就会找不到头文件
                "-std=c++1z" // c++1z即c++17,C语言最新标准为c11,或根据自己的需要进行修改 
            ], // 编译命令参数 
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true // 设为false可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
            },
            "presentation": {
                "echo": true,
                "reveal": "silent", // 设置是否在“终端”中显示编译信息,可以为always,silent,never。一些错误提示也在这里,但是因为有静态检测,我就设为silent了。 
                "focus": false,
                "panel": "shared" // 不同的文件的编译信息共享一个终端面板
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "/"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", // 正则表达式,用于描述在“问题”栏中显示的信息。
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            } // 1.11.0的更新日志里说可以直接写"problemMatcher": "$gcc",但是我试了一下不行。
        }
    ]
}

安装的插件有:

实现了正常的输出:

标签:code,++,llvm,clang,编译,vs,c++,file,LLVM
来源: https://www.cnblogs.com/naive-popo/p/16062124.html