C++20 使用 Visual Studio 编译模块:不编译或导入 ixx 文件
C++20 compiling modules with Visual Studio: doesn't compile or import ixx files
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 无效。解决方法是什么?
模块声明 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 扩展名
解决方案:
- 将 greeting.ixx 添加到头文件。 (将其添加到源文件中将不起作用。)
- 右键单击 greeting.ixx 上的属性,然后
- 将项目类型设置为 C/C++ 编译器
- 将 Excluded from Build 设置为 No.
- 保存
- 建造
好像有点不靠谱。除非我先进行清理,否则重建失败。
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 无效。解决方法是什么?
模块声明 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 扩展名解决方案:
- 将 greeting.ixx 添加到头文件。 (将其添加到源文件中将不起作用。)
- 右键单击 greeting.ixx 上的属性,然后
- 将项目类型设置为 C/C++ 编译器
- 将 Excluded from Build 设置为 No.
- 保存
- 建造
好像有点不靠谱。除非我先进行清理,否则重建失败。