Can I import in the global module fragment?
21:17 22 Dec 2025

I used to have headers that looked like this:

#include "glm/vec2.h"

struct Foo
{
    glm::vec2 myvec;

};

Now instead of including the glm headers I've decided to make a glm_module.cppm and export the vector typedefs, so I have:

module;
#include "glm/vec2.h"
export module glm_module;

export using myvec2 = glm::vec2;

And this is pretty run-of-the-mill conversion to modules. And it works. However now, since my vector types are in a module and not in headers to be included, obviously now I would want in my header file:

//#include "glm/vec2.h" // REMOVE THIS, NO LONGER INCLUDING
import glm_module;

class Foo
{
    myvec2 myvector;
}; 

Now, I would think this is fine, however this header that contains Foo, imagine now I want to include this header in a module. SomeOtherModule.cppm:

module;
#include "header_which_defines_foo.h"
export module SomeOtherModule;

Now, because "header_which_defines_foo.h" does "import glm_module", I'm essentially importing glm_module in the global module fragment:

module;
#include "header_which_defines_foo.h" // THIS IS THE GLOBAL MODULE FRAGMENT
export module SomeOtherModule;

And I heard you can't import in the global module fragment. Is this not possible?

c++ c++-modules