如何在VSCode中配置C++20格式的linter。

huangapple go评论121阅读模式
英文:

How to configure linter for VSCode with format C++20

问题

我正在使用 Windows 10 上的 VS Code 1.78.2,并使用 C/C++ 扩展以及 MinGW64 进行编译,命令如下:

$> g++ --version
g++ (x86_64-win32-seh-rev1, 由 MinGW-Builds 项目构建) 13.1.0
版权所有 (C) 2023 自由软件基金会,Inc.

我正在使用<format>,并将 -std=c++20 添加到我的编译标志,我的代码工作得很好。

但是在编辑器中,它一直显示错误。这可能是我配置不正确的 Linter,但在互联网上进行了一些研究和测试后,我没有找到问题出在哪里。

如何在VSCode中配置C++20格式的linter。

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win64",
            "includePath": [
                "${workspaceFolder}\\include\\**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

我不知道现在应该搜索什么,我的问题是:
如何配置我的 C/C++ 扩展以使我的 Linter 正确地与 format 头文件一起工作?

您是否遇到过这个问题?您有什么建议?

英文:

I'm using VS Code 1.78.2 with C/C++ extensions on Windows 10 and use MinGW64 for compiling so:

$&gt; g++ --version
g++ (x86_64-win32-seh-rev1, Built by MinGW-Builds project) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.

I'm using <format> and added -std=c++20 to my compilation flags and my code is working fine.

But when I'm in the editor, it's keep showing me an error. It's probably my linter that I misconfigured but after some research on the internet and some tests i didn't find what is wrong

如何在VSCode中配置C++20格式的linter。

c_cpp_properties.json

{
    &quot;configurations&quot;: [
        {
            &quot;name&quot;: &quot;Win64&quot;,
            &quot;includePath&quot;: [
                &quot;${workspaceFolder}\\include\\**&quot;
            ],
            &quot;defines&quot;: [
                &quot;_DEBUG&quot;,
                &quot;UNICODE&quot;,
                &quot;_UNICODE&quot;
            ],
            &quot;windowsSdkVersion&quot;: &quot;10.0.19041.0&quot;,
            &quot;compilerPath&quot;: &quot;C:\\mingw64\\bin\\g++.exe&quot;,
            &quot;cStandard&quot;: &quot;c17&quot;,
            &quot;cppStandard&quot;: &quot;c++20&quot;,
            &quot;intelliSenseMode&quot;: &quot;windows-gcc-x64&quot;,
            &quot;configurationProvider&quot;: &quot;ms-vscode.makefile-tools&quot;
        }
    ],
    &quot;version&quot;: 4
}

I don't know where to search now, my question is :
How to configure my C/C++ extension to get my linter properly works with the format header ?

Do you have met this problem ? do you have any advice ?

答案1

得分: 1

最后,我找到了一个解决方案,但在答案背后有逻辑。

在继续我的项目时,我遇到了其他头文件包含的问题,有时被智能感知检测到,有时没有。这给我浪费了很多时间。这是在VS Code上使用的C/C++扩展的随机行为。

正如我之前所说,我使用的是MinGW64,我的C/C++扩展使用它的编译器进行智能感知。但MinGW是GNU工具的一种适应版本,它们设计用于在Linux系统上运行,可能具有一些特定的头文件。

然而,Windows有自己的标准编译工具:Microsoft Visual C++ (MSVC) 使用 'cl',它们被设计成与最新版本的Windows轻松配合使用,因此MSVC的头文件应该在Windows系统上比GNU更好地工作

所以我按照这个教程安装了MSVC:https://code.visualstudio.com/docs/cpp/config-msvc

然后,我重新配置了我的C/C++扩展以使用MSVC,神奇的是,智能感知完美地工作了,即使是头文件格式。

英文:

Finally, I found a solution but behind the answer there is logic.

While continuing my project, I encountered other header inclusion problems that were sometimes detected, sometimes not by the intellisense. A random behavior of my C/C++ extension on VS Code which was wasting a lot of my time..

As I said before, I was using MinGW64 and my C/C++ extension uses its compiler for intellisense. But MinGW is an adaptation of the GNU tools which are designed to work on a Linux system with probably some specific headers for that.

However, Windows has its own standard compilation tools: Microsoft Visual C++ (MSVC) with 'cl' which have been designed in the same way to work easily with the latest versions of Windows and therefore the headers of MSVC should work better than those of GNU for a Windows system.

So I installed MSVC by following this tutorial: https://code.visualstudio.com/docs/cpp/config-msvc

Then I re-configured my C/C++ extension to use MSVC and magic, the intellisense works perfectly well, even with the header format

huangapple
  • 本文由 发表于 2023年5月29日 06:55:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定