简体   繁体   中英

How to include C++20 modules in Visual Studio Code

I'm writing C++20 code in Visual Studio Code. My configuration looks like this:

File 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
}

File 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."
        }
    ]
}

Everything looks fine until I try to use syncstream , which is introduced in C++20.

When I run #include <syncstream> , the compiler always gives me an error:

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

How should I configure in my Visual Studio Code so that the compiler can use C++20 modules?

See "Synchronized buffered ostream" at https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features

You need libstdc++11. Your compiler (g++10) doesn't support syncstream yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM