Skip to content

Conversation

@greghuels
Copy link
Collaborator

Fix C++20 modules compilation on macOS

Fixes #44

Problem

The SDK failed to compile on macOS when C++20 modules were enabled with the -fmodules flag. The build produced four compilation errors in the nlohmann JSON library:

  1. definition of 'basic_streambuf' must be imported from module 'std.streambuf' before it is required (line 6261)
  2. use of undeclared identifier 'errno' (line 8620)
  3. use of undeclared identifier 'errno' (line 8630)
  4. use of undeclared identifier 'errno' (line 8646)

Root Cause

When C++20 modules are enabled, the visibility of standard library includes becomes more restricted. The nlohmann JSON library is a single-header library with includes scattered throughout different sections. Previously, includes from one section were implicitly available in other sections, but with C++20 modules, each section requires explicit includes for the symbols it uses.

Solution

Added two missing standard library includes to third_party/nlohmann/json.hpp:

  1. Added #include <cerrno> at line 7381 in the lexer section

    • Fixes the three "undeclared identifier 'errno'" errors
    • The errno macro is used when parsing numbers in the lexer
  2. Added #include <streambuf> at line 6162 in the input adapters section

    • Fixes the "basic_streambuf must be imported" error
    • Required for stream buffer operations even though <istream> is present

Testing

  • ✅ Verified the library builds successfully with standard C++17 configuration (existing build)
  • ✅ Verified the library builds successfully with -fmodules flag enabled
  • ✅ All compilation errors from issue Problems with MacOS builds in 2.0.0 #44 are resolved
  • ✅ Maintains backward compatibility with existing builds

Changes

  • third_party/nlohmann/json.hpp: Added 2 include statements for C++20 modules compatibility

Copy link
Member

@leoromanovsky leoromanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there additional github CI that you can add which will validate this?

@greghuels
Copy link
Collaborator Author

Is there additional github CI that you can add which will validate this?

@leoromanovsky Great call! I updated with an additional CI check for this specific scenario.

@greghuels greghuels closed this Jan 13, 2026
@greghuels greghuels reopened this Jan 13, 2026
@dd-oleksii
Copy link
Collaborator

@greghuels have you considered submitting this fix upstream?

@greghuels
Copy link
Collaborator Author

greghuels commented Jan 13, 2026

@greghuels have you considered submitting this fix upstream?

It's probably worth doing this, yes, but I don't want it to hold up existing users.

Co-authored-by: Oleksii Shmalko <oleksii.shmalko@datadoghq.com>
@greghuels greghuels merged commit 315f4e1 into main Jan 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with MacOS builds in 2.0.0

4 participants