Install vs code in deepin 15.5 and configure the c/c++ environment (2) - configure clang

Continued from above: https://blog.csdn.net/defetc/article/details/79946100

Configuration file reference for this article: https://www.zhihu.com/question/30315894/answer/154979413

1. Install clang

    apt-get install clang

Second, install vs code related plugins

    C/C++ Clang Command Adapter

3. Modify the configuration file

    tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build", // task name, corresponding to preLaunchTask of launch.json
            "command": "clang++", // compiler to use
            "args": [
                "${file}",
                "-o", // Specify the output file name, if this parameter is not added, a.exe will be output by default
                "${fileDirname}/${fileBasenameNoExtension}.out",
                "-g", // generate and debug information
                "-Wall", // enable additional warnings
                "-static-libgcc", // static link
                "-fcolor-diagnostics",
                //"--target=x86_64-w64-mingw", // The default target is msvc, if this is not added, the header file will not be found
                "-std=c++14" // The latest standard of C language is c11, or modify it according to your own needs
            ], // compile command parameters
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true // Set to false to configure multiple compilation instructions in one tasks.json, you need to modify this file yourself, I won't mention it here
            },
            "presentation": {
                "echo": true,
                "reveal": "always", // The strategy for displaying compilation information in the "terminal", which can be always, silent, never. For details, see the VSC documentation
                "focus": false, // Set to true to focus on the terminal when executing the task, but for compiling c and c++, setting true is meaningless
                "panel": "shared" // The compilation information of different files shares a terminal panel
            }
            // "problemMatcher":"$gcc" // If you don't use clang, remove the preceding comment and add a comma after the previous entry. Follow my tutorial without changing (you can also delete this line)
        }
    ]
}

    "-std=c++14" is modified here according to your own situation, and the following settings.json are the same.

settings.json:

{
    "files.associations": {
        "iostream": "cpp",
        "ostream": "cpp"
    },
    //"files.defaultLanguage": "cpp", // ctrl+N the default language after creating a new file

    "code-runner.runInTerminal": true, // If set to false, it will be output in "output" and cannot be interacted with
    "code-runner.executorMap": {
        //"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.out -g -Wall -static-libgcc -fcolor-diagnostics -std=c11 && $dir$fileNameWithoutExt",
        //"cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.out -g -Wall -static-libgcc -fcolor-diagnostics -std=c++14 && $dir$fileNameWithoutExt"
        }, // Set the command line of the code runner
    "code-runner.saveFileBeforeRun": true, // run code前保存
    "code-runner.preserveFocus": true, // If false, the cursor will focus on the terminal after running the code. If you need to enter data frequently, it can be set to false
    "code-runner.clearPreviousOutput": false, // Clear the terminal messages belonging to the code runner before each code run

    "C_Cpp.clang_format_sortIncludes": true, // Adjust the order of includes when formatting (alphabetically)
    "C_Cpp.intelliSenseEngine": "Default", // Can be Default or Tag Parser, the latter is older and has simpler functions. For specific differences, refer to the cpptools plugin documentation
    "C_Cpp.errorSquiggles": "Disabled", // Disabled because of clang's lint
    "editor.formatOnType": true, // Formatting when inputting, the default trigger character is less, semicolon can trigger
    "editor.snippetSuggestions": "top", // snippets code shows completion first

    "clang.cflags": [ // Parameters that control static detection of c language
        //"--target=x86_64-w64-mingw",
        "-std=c11",
        "-Wall"
    ],
    "clang.cxxflags": [ // Parameters that control c++ static detection
        //"--target=x86_64-w64-mingw",
        "-std=c++14",
        "-Wall"
    ],
    //"clang.completion.enable":false // The effect is slightly better, but it is too stuck, so turn it off
}

    There are several other plugin configurations: "code runner", "C/C++ Snippets". The "code-runner.executorMap" configuration of "code runner" was commented out by me. It was originally intended to make the code runner also call clang, but unfortunately it will report an error in actual use. I don't know how to modify it, if anyone knows how to modify it, please point it out in the comment area!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324477628&siteId=291194637