简体   繁体   English

如何分发 C++20 模块?

[英]How to distribute C++20 modules?

All the literature about modules is quite recently new, and I am struggling with one core concept thing.所有关于模块的文献都是最近才出现的,我正在为一个核心概念而苦苦挣扎。

When I make my own modules, after the linkage process, does exists a conventional or accepted way of package those modules to distribute them as a library?当我制作自己的模块时,在链接过程之后,是否存在一种常规可接受的方式 package 这些模块将它们作为库分发?

Perhaps you are confusing modules and packages.也许您对模块和包感到困惑。 Modules is how the compiler sees code.模块是编译器查看代码的方式。 Packages are how the result of compiled code are distributed.包是编译代码结果的分发方式。 I do not think modules tackle the packaging problem at this point.我不认为模块在这一点上解决了包装问题。 There is a paper on the ISO committee but it is just a proposal at this point. ISO 委员会有一篇论文,但目前只是一个提案。

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2473r1.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2473r1.pdf

That said, it looks like all compilers are struggling to get modules up and running.也就是说,看起来所有编译器都在努力让模块启动和运行。 It is a tough problem to solve.这是一个很难解决的问题。 For example, macros are not possible to be exported with modules.例如,宏不能与模块一起导出。

At this point only MSVC supports it fully.目前只有 MSVC 完全支持它。 Gcc and Clang are partial only. Gcc 和 Clang 只是部分内容。 STL modules are not supported by any compiler at this point.目前任何编译器都不支持 STL 模块。

https://en.cppreference.com/w/cpp/compiler_support https://en.cppreference.com/w/cpp/compiler_support

Broadly speaking, the products of building a module's interface (as distinct from the linker-products of compilation, like a static/shared library) are not sharable between compilers.从广义上讲,构建模块接口的产品(与编译的链接器产品不同,如静态/共享库)在编译器之间是不可共享的。 At least not the way that compiled libraries for the same OS/platform are.至少不是为同一操作系统/平台编译库的方式。 Compiled module formats are compiler-specific and may not even be stable between versions of the same compiler.编译的模块格式是特定于编译器的,甚至可能在同一编译器的不同版本之间不稳定。

As such, if you want to ship a pre-compiled library that was build using modules, then just like non-module builds, you will need to ship textual files that are used to consume that module.因此,如果您想发布使用模块构建的预编译库,那么就像非模块构建一样,您需要发布用于使用该模块的文本文件。 Specifically, you need all of the interface units for any modules built into that library.具体来说,您需要该库中内置的任何模块的所有接口单元。 Implementation units need not be give, as their products are all in the compiled form of the library.不需要给出实现单元,因为它们的产品都是库的编译形式。

Perhaps in the future, compilers for the same platform will standardize a compiled module format, or even across platforms.也许在未来,同一平台的编译器将标准化编译的模块格式,甚至跨平台。 But until then, you're going to have to keep shipping text with your pre-compiled libraries.但在那之前,您将不得不继续使用您的预编译库发送文本。

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

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