使用clang链接C ++模块TS [英] Linking C++ modules TS using clang

查看:236
本文介绍了使用clang链接C ++模块TS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将c ++模块TS与clang一起使用。

I'm trying to use C++ modules TS with clang.

我创建了两个文件:

// foo.cppm
export module foo;

export void test() {
}

// bar.cpp
import foo;

int main() {
  test();
  return 0;
}

我编译 foo.cppm 使用此命令

clang++ --std=c++17 -fmodules-ts --precompile foo.cppm -o foo.pcm

它编译时没有错误,并创建了 foo.pcm 文件,但是当我尝试使用此命令编译二进制文件时:

It compiles without an error and creates a foo.pcm file, but when i try to compile a binary with this command:

clang++ --std=c++17 -fmodules-ts -fprebuilt-module-path=. -fmodule-file=foo.pcm bar.cpp

它会显示错误:

/tmp/bar-f69a1f.o: In function `main':
bar.cpp:(.text+0x10): undefined reference to `test()'

我尝试了clang 7主干和clang6。
我也尝试了不同的 std 选项和以下命令:

I tried it with clang 7 trunk and clang 6. Also i tried different std options and this command:

clang++ --std=c++17 -fmodules-ts -fmodule-file=foo.pcm bar.cpp -o bar

没有任何帮助。

足够有趣,如果一个模块使用其他模块的符号,则clang会编译这些模块。因此,据我了解,该问题处于链接阶段。

Interesting enough that if one module uses symbols from other, clang compiles these modules. So as i understand the problem is in linking stage.

可能是个问题吗?

推荐答案

就像> https://blogs.msdn.microsoft.com/vcblog/2015/12/03/c-modules-in- vs-2015-update-1 / 说,.cppm(.ixx)转换为.pcm(.ifc) .o(.obj)。

Like what https://blogs.msdn.microsoft.com/vcblog/2015/12/03/c-modules-in-vs-2015-update-1/ says, .cppm (.ixx) translates to .pcm (.ifc) and .o (.obj).

但是与cl.exe自动生成这两个文件不同,Clang的.o文件必须从其.pcm文件进行编译:

But unlike cl.exe, which automatically produce these two files, Clang's .o file must be compiled from its .pcm file:

clang++ --std=c++17 -fmodules-ts -c foo.pcm -o foo.o

使用上面的 foo.cppm bar.cpp ,命令将是像这样:

With foo.cppm and bar.cpp above, the commands would be like:

clang++ --std=c++17 -fmodules-ts --precompile foo.cppm -o foo.pcm
clang++ --std=c++17 -fmodules-ts -c foo.pcm -o foo.o
clang++ --std=c++17 -fmodules-ts -fprebuilt-module-path=. foo.o bar.cpp

这篇关于使用clang链接C ++模块TS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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