Skip to content

Conversation

@zacharykeyessonos
Copy link

@zacharykeyessonos zacharykeyessonos commented Oct 31, 2025

Description

This fixes #10490.

This fixes a compiler error when building C++ projects that use the 'modules' C++ language feature consume Mbed TLS. The specific error is module-import-in-extern-c, which occurs when #includes occur within extern C blocks.

Example:

$ clang-17 -std=c++20 -fmodules -Iinclude sample.cpp     
In file included from sample.cpp:2:
In file included from include/mbedtls/platform_util.h:18:
include/mbedtls/platform_time.h:33:1: error: import of C++ module '_Builtin_stdint' appears within extern "C" language linkage specification [-Wmodule-import-in-extern-c]
   33 | #include <stdint.h>
      | ^
include/mbedtls/platform_time.h:16:1: note: extern "C" language linkage specification begins here
   16 | extern "C" {
      | ^
include/mbedtls/platform_time.h:34:1: error: import of C++ module '_Builtin_inttypes' appears within extern "C" language linkage specification [-Wmodule-import-in-extern-c]
   34 | #include <inttypes.h>
      | ^
include/mbedtls/platform_time.h:16:1: note: extern "C" language linkage specification begins here
   16 | extern "C" {
      | ^
2 errors generated.

This seems to primarily be an issue with clang. See https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fmodules

PR checklist

This fixes a compiler error when building C++ projects that use the
'modules' C++ language feature consume Mbed TLS. The specific error is
module-import-in-extern-c, which occurs when `#include`s occur within
`extern C` blocks.

```
$ clang-17 -std=c++20 -fmodules -Itf-psa-crypto/include -Itf-psa-crypto/drivers/builtin/include -o sample sample.cpp
In file included from sample.cpp:8:
In file included from tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h:44:
tf-psa-crypto/drivers/builtin/include/mbedtls/private/chacha20.h:26:1: error: import of C++ module '_Builtin_stdint' appears within extern "C" language linkage specification [-Wmodule-import-in-extern-c]
   26 | #include <stdint.h>
      | ^
tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h:35:1: note: extern "C" language linkage specification begins here
   35 | extern "C" {
      | ^
1 error generated.
```

This seems to primarily be an issue with clang. See
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fmodules

Signed-off-by: zacharykeyessonos <zachary.keyes@sonos.com>
@zacharykeyessonos zacharykeyessonos changed the title Fix module-import-in-extern-c compiler error Fix module-import-in-extern-c compiler error (3.6) Oct 31, 2025
Signed-off-by: zacharykeyessonos <zachary.keyes@sonos.com>
Signed-off-by: zacharykeyessonos <zachary.keyes@sonos.com>
@zacharykeyessonos zacharykeyessonos force-pushed the fix-module-import-in-extern-c-compiler-error_3.6 branch from f1254b3 to 8add50f Compare November 4, 2025 17:46
@minosgalanakis minosgalanakis added size-s Estimated task size: small (~2d) bug component-platform Portability layer and build scripts priority-low Low priority - this may not receive review soon needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug component-platform Portability layer and build scripts needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review priority-low Low priority - this may not receive review soon size-s Estimated task size: small (~2d)

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

2 participants