简体   繁体   English

为什么这个 C++ 程序没有使用模块编译?

[英]Why does this C++ program does not compile using modules?

Sorry if i ask again about "moudules" in C++. Im using g++ gcc-c++-12.2.1-4.fc37.x86_64 in fedora 37 linux and vscode.抱歉,如果我再次询问 C++ 中的“模块”。我在 fedora 37 linux 和 vscode 中使用 g++ gcc-c++- 12.2.1-4.fc37.x86_64。 So i said: i will upgrade my knowladge with the book "A tour of C++ third edition" which its updated to c++20 standard.所以我说:我会用更新到 c++20 标准的书“C++ 第三版之旅”来升级我的知识。

The thing that the first program:第一个程序的东西:

import std;
int main()
{
std::cout << "Hello, World!\n";
}

Doesn't compile.不编译。 I have enabled "std=c++20" and "-fmodules-ts" and also tried "-std=gnu++20".我启用了“std=c++20”和“-fmodules-ts”,还尝试了“-std=gnu++20”。

The output is this, its like the compiled modules are missing: output 是这样的,就像缺少已编译的模块一样:

std: error: failed to read compiled module: No existe el fichero o el directorio
std: nota: compiled module file is ‘gcm.cache/std.gcm’
std: nota: imports must be built before being imported
std: error fatal: returning to the gate for a mechanical issue

Ok it's in spanish becouse is my native tongue.好的,这是西班牙语,因为是我的母语。 Any help?有什么帮助吗?

import std;

This line of code requires not only module support, but also Standard Library Modules ( P2465R3 Standard Library Modules std and std.compat ) that's part of C++23.这行代码不仅需要模块支持,还需要作为 C++23 一部分的标准库模块P2465R3 标准库模块 std 和 std.compat )。 From the Compiler support for C++23 page on cppreference, we can see that it's still not supported by GCC libstdc++.从 cppreference 上的Compiler support for C++23页面,我们可以看到 GCC libstdc++ 仍然不支持它。


As OP mentioned that the code snippet is taken from Bjarne's book, I double-checked section 1.2 of it.正如 OP 提到的代码片段取自 Bjarne 的书,我仔细检查了它的第 1.2 节。 In the paragraph after the next from the code snippet containing import std;在包含import std; , it's stated that this is not yet standard: ,据说这还不是标准的:

The import directive is new in C++20 and presenting all of the standard library as a module std is not yet standard. import 指令是 C++20 中的新指令,将所有标准库作为模块 std 呈现还不是标准。 [...] [...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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