无法使用 g++ 9.3.0 编译 C++20 代码

问题描述 投票:0回答:1

我正在尝试使用g ++ 9.3.0使用文档中提到的标志来编译C ++ 20代码,但我遇到了错误

#include <iostream>
#include <span>

void span_test() {
    constexpr int a[] = {0, 1, 2, 3, 4};
    auto s = std::span{a};

    std::cout << s.size() << std::endl;
} 

int main() {
    span_test();
    return 0;
}

我知道这不是与 C++20 兼容的最新版本的 g++。我需要使用 g++ 9.3.0 创建共享对象文件,因为我受到 Xcelium 的限制。

g++ -c -std=c++2a -fPIC libdpi.cpp -o libdpi.o

libdpi.cpp:2:10: fatal error: span: No such file or directory
    2 | #include <span>
      |          ^~~~~~
compilation terminated.
g++
1个回答
0
投票

g++ 9.3.0不支持span,g++ 10以上支持span。

参见 https://en.cppreference.com/w/cpp/compiler_support/20

© www.soinside.com 2019 - 2024. All rights reserved.