不确定现在是否支持import <module_Name>;。当我试图运行一个程序,包括模块,它统计note: c++20 'import' only available with '-fmodules-ts'是像-std=c++20这样的编译器标志,或者是目前不支持的模块。下面是一个使用模块的示例程序:
#include<iostream>
import <numbers>;
import <format>;
int main()
{
double pi {std::numbers::pi};
std::cout << std::format("Pi is = to {}", pi);
}我知道我可以使用#include <numbers>,但我正在试图找出模块是否工作。我不太确定是否可以使用<import>添加#include。
编辑10/8/21: I编写了一个二级程序,删除<format>和std::format(),使用-fmodules-ts标志测试import <numbers>;的实现,但仍然没有工作。请参阅下面的程序和终端。
节目:
#include<iostream>
import <numbers>;
int main()
{
double pi {std::numbers::pi};
std::cout << pi;
}航站楼:
g++ randomCodeWhileReading.cpp -o main -std=c++2a -fmodules-ts
randomCodeWhileReading.cpp:2:1: error: unknown Compiled Module Interface: no such module
2 | import <numbers>;
| ^~~~~~
In module imported at randomCodeWhileReading.cpp:2:1:
/usr/include/c++/11/numbers: error: failed to read compiled module: Unknown CMI mapping
/usr/include/c++/11/numbers: note: imports must be built before being imported
/usr/include/c++/11/numbers: fatal error: returning to the gate for a mechanical issue
compilation terminated.发布于 2022-09-08 03:55:48
@ExZerminator,你是对的。已完成:
# g++ -std=c++20 -fmodules-ts hello.cpp -o hello.exe -x c++-system-header iostreamhttps://stackoverflow.com/questions/69502406
复制相似问题