Visual Studio Code安装以及C/C++运行环境搭建实战(3)

如果你没有合并Clang和MinGW,则该文件中头文件的路径必需修改成MinGW的路径,否则Lint无效。版本号(这里是7和7.1.0)如果不同,也要修改。输gcc -v可以看到)

Windows下的路径为反斜杠,原本应使用两个反斜杠来转义,但直接用斜杠在VS Code中也接受

// 将设置放入此文件中以覆盖默认值和用户设置。
{
    "files.defaultLanguage": "c", // ctrl+N新建文件后默认的语言
    "c-cpp-flylint.cppcheck.enable": false,
    "c-cpp-flylint.flexelint.enable": false,
    "c-cpp-flylint.run": "onType", // 此选项貌似不起作用
    "c-cpp-flylint.clang.includePaths": [
        "${workspaceRoot}",
        "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++",
        "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/x86_64-w64-mingw32",
        "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/backward",
        "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
        "C:/llvm/include",
        "C:/llvm/x86_64-w64-mingw32/include",
        "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed"
    ],
    "c-cpp-flylint.clang.defines": [
        "_DEBUG",
        "UNICODE",
        "__GNUC__=7",
        "__cdecl=__attribute__((__cdecl__))"
    ],
    "c-cpp-flylint.standard": [
        "c11", // 如果你想要使用c89,就自己改
        "c++1z" // c++1z即c++17
    ],
    "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法交互
    "code-runner.executorMap": {
        "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c++1z && $dir$fileNameWithoutExt"
    },
    "code-runner.saveFileBeforeRun": true,
    "C_Cpp.clang_format_sortIncludes": true,
    "C_Cpp.errorSquiggles": "Disabled"
}

c_cpp_properties.json代码:

如果你没有合并Clang和MinGW,则该文件中头文件的路径必需修改成MinGW的路径,否则IntelliSense无效。版本号如果不同,也要修改。

{
    "configurations": [
        {
            "name": "Win32",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++",
                "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/x86_64-w64-mingw32",
                "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/backward",
                "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                "C:/llvm/include",
                "C:/llvm/x86_64-w64-mingw32/include",
                "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=7",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "browse": {
                "path": [
                    "C:/llvm/x86_64-w64-mingw32/include",
                    "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                    "C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
                    "C:/llvm/include/*",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 2
}

然后就可以在工作区进行编写代码了。

四、其他

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12214.html