Skip to content

Commit 67b64bc

Browse files
Fix module-import-in-extern-c compiler error
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 <[email protected]>
1 parent 32b597b commit 67b64bc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/mbedtls/timing.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
#include <stdint.h>
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
21-
2218
#if !defined(MBEDTLS_TIMING_ALT)
2319
// Regular implementation
2420
//
@@ -43,6 +39,10 @@ typedef struct mbedtls_timing_delay_context {
4339
#include "timing_alt.h"
4440
#endif /* MBEDTLS_TIMING_ALT */
4541

42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
4646
/* Internal use */
4747
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset);
4848

0 commit comments

Comments
 (0)