How do I use C++ modules in Clang?

前端 未结 2 574
你的背包
你的背包 2020-12-08 19:04

Modules are an alternative to #includes. Clang has a complete implementation for C++. How would I go about if I wanted to use modules using Clang now?


Using

2条回答
  •  一个人的身影
    2020-12-08 19:47

    Like you mentioned, clang does not yet have a C++ syntax for imports, so I doubt that #include directives are going to be literally rewritten as imports when preprocessing a file, so that may not be the best way to test if modules are working as intended.

    However, if you set -fmodules-cache-path= explicitly, you can observe clang populating it with precompiled module files (*.pcm) during a build - if there are any modules involved.

    You'll need to use libc++ (which seems to come with a module.modulemap as of version 3.7.0) if you want to use a modules enabled standard library right now - though in my experience this isn't working entirely just yet. (Visual Studio 2015's C++ compiler is also supposed to get some form of module support with Update 1 in November)

    Independently of the stdlib, you could still use modules in your own code. The clang docs contain a detailed description of the Module Map Language.

提交回复
热议问题