【问题标题】:How to include C++20 modules in Visual Studio Code如何在 Visual Studio Code 中包含 C++20 模块
【发布时间】:2021-02-23 17:57:55
【问题描述】:

我正在 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 模块?

【问题讨论】:

  • 我建议使用合适的构建系统,例如 CMake。 VScode 有一个 CMake 扩展,可以使用编辑器中的单个命令进行编译。

标签: c++ visual-studio-code vscode-settings c++20


【解决方案1】:

请参阅https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features 上的“同步缓冲 ostream”

您需要 libstdc++11。你的编译器 (g++10) 还不支持syncstream

【讨论】:

  • 谢谢!!我只是寻找 libstdc++11 的安装,但找不到任何东西。你能告诉我如何安装它吗?谢谢!
  • 如果你安装 g++11,它应该带有 libstdc++11。
猜你喜欢
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
  • 2018-02-16
  • 2019-12-02
  • 1970-01-01
  • 2021-10-22
  • 2017-09-16
  • 1970-01-01
相关资源
最近更新 更多