簡體   English   中英

如何在 Visual Studio Code 中包含 C++20 模塊

[英]How to include C++20 modules in Visual Studio Code

我正在 Visual Studio Code 中編寫 C++20 代碼。 我的配置如下所示:

文件c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/local/Cellar/gcc/10.2.0/bin/g++-10",
            "cStandard": "c11",
            "cppStandard": "c++20",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

文件tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/local/Cellar/gcc/10.2.0/bin/g++-10",
            "args": [
                "-g",
                "-pthread",
                "-std=c++20",
                "-I/usr/local/Cellar/gcc/10.2.0/include",
                "-I/usr/local/Cellar/fmt/7.1.3/include",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

在我嘗試使用 C++20 中引入的syncstream之前,一切看起來都很好。

當我運行#include <syncstream>時,編譯器總是給我一個錯誤:

fatal error: syncstream: No such file or directory
    5 | #include <syncstream>
      |          ^~~~~~~~~~~~
compilation terminated.

我應該如何在我的 Visual Studio Code 中進行配置,以便編譯器可以使用 C++20 模塊?

請參閱https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features上的“同步緩沖 ostream”

你需要 libstdc++11。 您的編譯器 (g++10) 還不支持syncstream

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM