简体   繁体   中英

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?

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.

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. Gcc and Clang are partial only. STL modules are not supported by any compiler at this point.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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