gpt4 book ai didi

c++ - Clangs C++ 模块 TS 支持 : How to tell clang++ where to find the module file?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:12 24 4
gpt4 key购买 nike

在他的talk在 CppCon 上,Richard Smith 提到尽管 Module TS 支持目前正在进行中,但它已经可以使用了。所以我从 svn 构建了 clang 4.0,并在一个非常简单的示例上进行了尝试。在我的 myclass.cppm 文件中,我为 int

定义了一个简单的包装器
 module myclass;

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

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

和我的 main.cpp 只是创建该类的一个实例,并将其保存的 int 输出到 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.cppclang++ -std=c++1z -fmodules-ts myclass 编译它.cppm main.cpp 但这不起作用,在这两种情况下我都收到相同的错误消息:

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

很遗憾,我无法找到-fmodules-ts 的文档。有人知道如何让 clang++ 编译我的简单示例吗?

最佳答案

你可以这样编译它:

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

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

关于c++ - Clangs C++ 模块 TS 支持 : How to tell clang++ where to find the module file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39818600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com