C++20 用 Visual Studio 编译模块:不编译或导入 ixx 文件

Top*_*ort 1 c++ visual-c++ c++20 c++-modules

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

export module greetings;

import std.core;

export std::string get_greeting_text()
{
    return "Hello, World!";
}
Run Code Online (Sandbox Code Playgroud)

这是主要的:

import std.core;
import greetings;

int main()
{
    std::cout << get_greeting_text() << '\n';
}
Run Code Online (Sandbox Code Playgroud)

我确实设置了这些标志:/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
Run Code Online (Sandbox Code Playgroud)

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

Top*_*ort 8

解决方案:

  • 将 greeting.ixx 添加到头文件。(将其添加到源文件中是行不通的。)
  • 右键单击 greeting.ixx 上的属性,然后
    • 将项目类型设置为 C/C++ 编译器
    • 将“从构建中排除”设置为“否”。
    • 节省
  • 建造

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