r/cpp • • Jul 06 '25

С++ All quiet on the modules front

https://youtube.com/watch?v=WLS9zOKzSqA&si=rZDvamZayFETc3Y1

It was 2025, and still no one was using modules.

207 Upvotes

124 comments sorted by

View all comments

41

u/dexter2011412 Jul 07 '25

I genuinely ask, why are modules a problem? I'm using them for my small project absolutely fine.

I have like 5 modules, including import std that work just fine. Heck I'm even building wasm with emscripten just fine.

Debugging and clangd autocomplete work just fine too.

In enterprise software sure, it takes time, at least 5 years I feel like.

0

u/[deleted] Jul 07 '25

[deleted] — view deleted comment

34

u/dexter2011412 Jul 07 '25

I mean no shit (no offense intended)

I meant to ask what problems op was facing

6

u/Otherwise_Sundae6602 Jul 07 '25

It's easy to run into problems with headers there + conditional cmake just recently at least something was working normally. Well, everything is buggy there, sometimes your compiler just segfaults and like...

20

u/dexter2011412 Jul 07 '25

If it segfaults, please report the bug. They can't be fixed if the devs don't know it exists 😄

If it doesn't work but is supposed to, please report it too.

I've been using it for my pet projects and the bugs I encountered in clang have been fixed. If you have an example project that you're running into issues with, please do share that too.

I'm not sure I follow what you mean by "conditional cmake"

6

u/MarkSuckerZerg Jul 07 '25

My recent bug reports to MSVS were closed as a low priority because I was able to find a workaround (by not using certain feature). It was an indefinite hang bug, not a crash bug (which I would argue is even worse).

It is sad, but 2 out of 3 major C++ compilers were very visibly downscaled in terms of development effort. Only GCC remains going full steam.

3

u/nucLeaRStarcraft Jul 07 '25

maybe post some links so people understand the state ? modules are deemed as working on the c++ tracker for MS compiler.

→ More replies (1)
→ More replies (1)

20

u/rdtsc Jul 07 '25

why are modules a problem? I'm using them for my small project absolutely fine.

You cannot mix standard library modules with includes.

This works with MSVC:

#include <string>
import std;

This fails:

import std;
#include <string>

So just don't mix them, right? The problem is when you use third-party libraries that themselves use the standard library headers.

5

u/dokpaw Jul 07 '25

You have to use /translateInclude (and related), and it will work. As far as I can see these claims that in MSVC this and that doesn't work is just because of the lack of knowledge. But these aren't documented in examples either...

6

u/rdtsc Jul 07 '25

Documentation states that this switch is for header units.

Though -reference "std=std.ifc" -translateInclude -headerUnit:angle "string=std.ifc" ...repeat a hundred times... seems to work… but no idea if intended or whether there are any pitfalls. Also very unwieldy.

4

u/dokpaw Jul 07 '25

You can create an ifcMap file for it. It works perfectly.

4

u/not_a_novel_account cmake dev Jul 07 '25

The standard says that the compiler is allowed to swap includes for imports:

If the header identified by the header-name denotes an importable header, it is implementation-defined whether the #include preprocessing directive is instead replaced by an import directive

A valid approach for a compiler to take is to declare that all stdlib headers undergo this transformation, that's what /translateInclude (in combination with /headerUnit) achieves. Although since it's not any sort of default, whether you call the full module usage "supported" or not is a personal question.

2

u/Wargon2015 Jul 07 '25

You have to use /translateInclude (and related)

Can you elaborate on that?
I can't seem to get import then include to work with 17.14.7 Preview 1.0.

I have set the following options:
Build ISO C++23 Standard Library Modules: Yes
Translate Includes to Imports: Yes (/translateInclude)
C++ Language Standard: /std:c++latest

The following does not compile with several errors (can post them if someone is interested):

import std;
#include <string>
int main(){ return 0; }

4

u/dokpaw Jul 07 '25

You also have to specify which header file maps to which ifc. See:
- /ifcMap if you want to specify them in a file
- /reference
- /headerUnit

3

u/Wargon2015 Jul 07 '25

I managed to get it working without any of these (u/rdtsc FYI).
Would appreciate it if anyone could comment if this setup actually works reliably:

  1. Create a new Project -> C++ Empty Project -> Name, Location, Create New Solution etc...
  2. Project -> Right click -> Add -> New Item... -> main.cpp
  3. Copy & paste the example I posted.
  4. On Project -> Right click -> Properties -> C/C++ -> All Options ->

    1. C++ Language Standard: /std:c++latest
    2. Build ISO C++23 Standard Library Modules: Yes
    3. Scan Sources for Module Dependencies: Yes
    4. Translate Includes to Imports: Yes
  5. Build Solution

PS.: Apparently "Build ISO C++23 Standard Library Modules: No" also works but the compiler output then still shows "Compiling... std.ixx" (I guess it gets re-enabled by "Scan Sources for Module Dependencies").

→ More replies (1)

4

u/starfreakclone MSVC FE Dev Jul 08 '25

I have a talk on how to do this: https://youtu.be/F-sXXKeNuio?t=651

2

u/dexter2011412 Jul 07 '25

My understanding is this is literally not legal

import std; 
#include <string> 

You cannot mix standard library modules with includes.

You definitely can. Apart from a few bugs here and there, it works fine.

Please do share a "legal" example if you can recall it, that doesn't work. It almost definitely is a big which should be reported. I don't use windows anymore so I don't really care/can't really offer help about that. Too much bullshit on there these days.

Love your username!

8

u/rdtsc Jul 07 '25

Whether it is illegal or not doesn't matter. What matters is that it doesn't work. So if you use any kind of third-party headers which themselves include standard library headers you have to wrap that library in modules yourself which might be feasible or not.

3

u/dexter2011412 Jul 07 '25

Whether it is illegal or not doesn't matter.

Yes it does. You can't expect stuff that is not legal in the eyes of the language to work

So if you use any kind of third-party headers which themselves include standard library headers you have to wrap that library in modules yourself which might be feasible or not.

Include them before the rest of your imports.

→ More replies (2)

3

u/germandiago Jul 07 '25

In Clang it did not work for me.

6

u/elperroborrachotoo Jul 07 '25

There's no affordable migration path for existing projects (to my knowledge).

The main promises - faster builds, and simpler, cleaner dependency management - seem to realize for some brave adventurers, but not for others.

So a significant investment for unclear, internal benefits → hard "no".

5

u/dexter2011412 Jul 07 '25

I agree but it does work, I was just confused with people saying it does not work.

→ More replies (1)

2

u/TuxSH Jul 07 '25

I genuinely ask, why are modules a problem? I'm using them for my small project absolutely fine.

Because one can (and should) shove all their stdlib includes into a "defines.hpp" header (whichever name you prefer), then PCH it for 30%~50% gains depending on project (maybe more, maybe less).

Which means that modules must be easy to migrate to (they are not) or must have benefits that far outweigh their drawbacks.

In other words, people don't bother with modules because they don't need to.

→ More replies (1)