【问题标题】:C++20 compiling modules with Visual Studio: doesn't compile or import ixx files使用 Visual Studio 编译 C++20 模块:不编译或导入 ixx 文件
【发布时间】:2020-10-07 18:34:54
【问题描述】:

Visual Studio 2019 不会尝试编译我的 .cxx 或 .ixx 文件。这是我的 .cxx 文件:

export module greetings;

import std.core;

export std::string get_greeting_text()
{
    return "Hello, World!";
}

这是主要的:

import std.core;
import greetings;

int main()
{
    std::cout << get_greeting_text() << '\n';
}

我确实设置了这些标志:/std:c++latest/experimental:module。错误信息是

C:\...\main.cpp(2,17):error C2230: could not find module 'greetings'
C:\...\main.cpp(6,2): error C3861: 'get_greeting_text': identifier not found

...但是我没有看到任何关于尝试编译 greetings.cxx 的行,所以这一定是问题所在。将其更改为 .ixx 无效。解决方法是什么?

【问题讨论】:

标签: c++ visual-c++ c++20 c++-modules


【解决方案1】:

解决方案:

  • 将 greeting.ixx 添加到头文件。 (将其添加到源文件将不起作用。)
  • 在 greeting.ixx 上右键单击属性,然后
    • 将项目类型设置为 C/C++ 编译器
    • 从构建中排除设置为否。
    • 保存
  • 构建

它似乎有点片状。除非我先进行清理,否则重建失败。

【讨论】:

  • 项目类型:“C/C++ 编译器”不是头文件,而是“C/C++ 头文件”。你的第一步想表达什么?
  • .ixx 文件不是头文件,但它确实需要由 C/C++ 编译器编译。试试看。
  • 这对我有帮助!!!因为我手动将 .h 更改为 .ixx ......我在这上面浪费了几个小时。
【解决方案2】:

模块声明 export module greetings; 尚未在 Visual Studio 2019 上运行。

您可以尝试为您的 greetings.cxx 文件添加以下编译器意见:

/module:export /module:name greetings /module:wrapper greetings.h /module:output greetings.ifc -c greetings.cxx

另一种解决方案,将 greetings.cxx 重命名为 greetings.ixx。 Visual Studio 中的模块接口文件需要 .ixx 扩展名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    相关资源
    最近更新 更多