Clangs C ++ Module TS支持:如何告诉clang ++在哪里找到模块文件? [英] Clangs C++ Module TS support: How to tell clang++ where to find the module file?

查看:315
本文介绍了Clangs C ++ Module TS支持:如何告诉clang ++在哪里找到模块文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Richard Smith在CppCon的对话中提到,即使Module TS支持目前正在开发中,已经可以使用。因此,我从svn构建了clang 4.0,并在一个非常简单的示例中进行了尝试。在我的 myclass.cppm 文件中,我为 int

In his talk at CppCon, Richard Smith mentioned that even though the Module TS support is currently work in progress, it can already be used. So I build clang 4.0 from svn and tried it on a very simple example. In my myclass.cppm file I defined a simple wrapper for an int

 module myclass;

 export class MyClass {
 public:
     MyClass (int i) 
          : _i{i} {}

     int get() {
          return _i;
     }
 private:
     int _i;
 }; 

和我的 main.cpp 仅创建一个该类的实例,并将其持有的 int 输出到 std :: cout

and my main.cpp just creates one instance of that class and outputs its held int to std::cout.

#include <iostream>
#include <string>
import myclass;

int main(int, char**) {
    MyClass three{3};
    std::cout << std::to_string(three.get()) << std::endl;
}

然后我尝试通过 clang ++ -std对其进行编译= c ++ 1z -fmodules-ts main.cpp clang ++ -std = c ++ 1z -fmodules-ts myclass.cppm main.cpp 但这不起作用,在两种情况下我都得到相同的错误消息:

Then I tried to compile it via clang++ -std=c++1z -fmodules-ts main.cpp and with clang++ -std=c++1z -fmodules-ts myclass.cppm main.cpp but that doesn`t work and I get the same error message in both cases:

main.cpp:3:8: fatal error: module 'myclass' not found
import test.myclass;
~~~~~~~^~~~
1 error generated.

不幸的是,我无法找到 -fmodules-ts 。有人知道我如何让clang ++编译我的简单示例吗?

Unfortunately I have not been able to find documentation for -fmodules-ts. Does someone know how I can get clang++ to compile my simple example?

推荐答案

您可以按以下方式进行编译:

You can compile it as follows:

clang++ -std=c++1z -fmodules-ts --precompile -o myclass.pcm myclass.cppm 
clang++ -std=c++1z -fmodules-ts -fmodule-file=myclass.pcm -o modules_test main.cpp

但是,这并不是它的工作原理,因为您需要在对编译器的调用中手动编码模块的依赖关系层次结构;我会对这个问题的正确答案非常感兴趣:-)。

However, this can't be how it's meant to work since you'd manually need to encode the dependency hierarchy of your modules in the calls to the compiler; I'd be very interested in the correct answer to this question :-).

这篇关于Clangs C ++ Module TS支持:如何告诉clang ++在哪里找到模块文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆