[Modules] How to export variables in the GMF

Hi,

consider the following code (Godbolt-Link):

C++
module;

namespace vk {
    constexpr int ApiVersion = 1;
}

export module foo;

export {
    using vk::ApiVersion;
}

This failed with: error: using declaration referring to 'ApiVersion' with internal linkage cannot be exported.

Is this a bug or expected behavior? If this is by design how should the variable be exported?

Thanks!

This is a language defect. See P2808R0: Internal linkage in the global module and P2788 Linkage for modular constants · Issue #1477 · cplusplus/papers · GitHub. And WG21 is still discussing about this.

For practical uses, you can add an inline specifier to the definition of ApiVersion .

1 Like