简体   繁体   English

clang 编译的模块 pcm 文件有什么用?

[英]What are clang's compiled module pcm files for?

I'm looking at the driver test cases for clang modules: https://github.com/llvm-mirror/clang/blob/master/test/Driver/modules.cpp我正在查看 clang 模块的驱动程序测试用例: https://github.com/llvm-mirror/clang/blob/master/test/Driver/modules.cpp

It includes steps to produce.pcm.o files.它包括生成.pcm.o 文件的步骤。 I'm wondering what they are for.我想知道它们是干什么用的。

Given a c++20 module给定一个 c++20 模块

// a-m.cc
module;
#include <iostream>
export module a;
export void do_a() { std::cout << "A\n"; }

You can compile it using您可以使用编译它

clang++ -std=c++20 -x c++-module --precompile a-m.cc -o a.pcm

which produces the precompiled module file a.pcm .它产生预编译的模块文件a.pcm

But there are also steps to compile.pcm files to.o files.但是也有将.pcm文件编译成.o文件的步骤。

From the driver tests :从驱动程序测试

clang++ -std=c++20 a.pcm -S -o a.pcm.o

How are the.pcm.o files meant to be used? .pcm.o 文件是如何使用的?

If I write a main program如果我写一个主程序

// main.cc
import a;

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

Compile with编译

clang++ -std=c++20 -c main.cc -fmodule-file=a=a.pcm

And then try to link with the.pcm.o, I get然后尝试与.pcm.o链接,我得到

clang++ main.o a.pcm.o
/usr/bin/ld:a.pcm.o: file format not recognized; treating as linker script
/usr/bin/ld:a.pcm.o:2: syntax error
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

Note: you can compile am.cc注意:可以编译 am.cc

clang++ std=c++20 -c a-m.cc -o a.o

and link with ao, but what are the.pcm.o files for?并与 ao 链接,但.pcm.o 文件是做什么用的? and can they be used to avoid compiling am.cc again after you've precompiled it?并且它们可以用来避免在您预编译 am.cc 后再次编译它吗?

The pcm-files contains "half baked" information about a module. pcm 文件包含有关模块的“半成品”信息。 The file extension does not have to be pcm and i think Visual Studio for example uses .ifc as extension.文件扩展名不必是 pcm,我认为例如 Visual Studio 使用.ifc作为扩展名。 (And a difference with Visual Studio is that it outputs the ifc-file and compiles the object file ( .obj ) at the same time, while clang does this in two separate steps) (与 Visual Studio 的不同之处在于它输出 ifc 文件并同时编译 object 文件( .obj ),而 clang 则分两个单独的步骤执行此操作)

The pcm file is storing the information about the module file in a format so that the compiler can easily import it or compile it to other object files. pcm 文件以某种格式存储有关模块文件的信息,以便编译器可以轻松地将其导入或编译为其他 object 文件。

The command from your link surprises me, I think that -S in the example is compiling to assembly, so i am surprised that it is listed in that clang repo that you linked to.您链接中的命令让我感到惊讶,我认为示例中的-S正在编译为程序集,所以我很惊讶它在您链接到的 clang 存储库中列出。

clang++ -std=c++20 a.pcm -S -o a.pcm.o # To mee this looks wrong (assembly output)

Try changing it to use -c instead尝试将其更改为使用-c

clang++ -std=c++20 a.pcm -c -o a.pcm.o # This is how you compile pcm-files to object files

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM