VC++ 实验模块不起作用



我正在尝试Visual Studio 2017版本15.4.4中模块的实验性实现。我按照此处描述的说明进行操作 https://blogs.msdn.microsoft.com/vcblog/2017/05/05/cpp-modules-in-visual-studio-2017/。我能够在控制台应用程序中快速运行。

import std.core;
int main()
{
   std::cout << "Hello modules!" << std::endl;
   return 0;
}

导入和使用可用的标准模块不是问题(就我尝试到目前为止而言(。

但是,当我定义自己的模块时,没有任何效果。我添加了一个文件系统.ixx(项目类型C/C++编译器(,内容如下:

import std.core;
export import system.io;
export struct console
{
   void write(std::string_view text) { std::cout << text; }
   void write_line(std::string_view text) { std::cout << text << std::endl; }   
};

当我将import system.io添加到主.cpp

import std.core;
import system.io;
int main()
{
   std::cout << "Hello modules!" << std::endl;
   return 0;
}

我收到以下错误:

1>system.ixx
1>system.ixx(2): error C2230: could not find module 'system.io'
1>main.cpp
1>main.cpp(2): error C2230: could not find module 'system.io'

我还在编译器选项中添加了/module:reference system.io.idf,但是没有从system.ixx生成的system.io.idf文件。

我知道这是实验性的,有很多问题,但我想知道我应该做些什么来使这个简单的事情工作。

system.ixx中,尝试将export import system.io更改为export module system.io。您还需要确保export module ...声明显示在文件顶部。所以system.ixx变成:

export module system.io;
import std.core;
export struct console
{
   void write(std::string_view text) { std::cout << text; }
   void write_line(std::string_view text) { std::cout << text << std::endl; }   
};

最新更新