C++20 Modules in Shared Libraries

Michael Brunner 40 Reputation points


Follow-up question to https://learn.microsoft.com/en-us/answers/questions/1665106/how-to-use-c-20-modules-in-shared-libraries

I’ve been exploring the use of C++20 modules in shared libraries and I understand the typical approach involves providing an .ifc file. However, I’m curious if there’s a way to utilize these modules without distributing the .ifc file. Could you provide guidance on how to use a DLL module in such a scenario?

  • Alternative Methods: Are there alternative methods to import modules without an .ifc file?
  • DLL Usage: How can one use the DLL module without the .ifc file in another project?
  • Build System Configuration: What changes are needed in the build system to support this usage?

Any insights or examples would be greatly appreciated

Thank you!

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 10,791 Reputation points Microsoft Vendor


    After testing

    Alternative Methods:

    1. Providing forward declarations

    Since the source file has been compiled into a DLL, all you need to do is provide the necessary declarations.


     void myFunction();
     class  Test;
       class Test
    //import test.modules;
    int main()

    Or 2. Right click project -> Add -> Existing item: your test.modules.ixx file to the project. (test.modules.cpp file is not needed)

    import test.modules;
    int main()

    The compiler will generate an ifc file for use in your project.

    Also, don't forget to link to the DLL.

    Best regards,

    Minxin Yu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful