diff --git a/ChangeLog.d/fix-module-import-in-extern-c-compiler-error.txt b/ChangeLog.d/fix-module-import-in-extern-c-compiler-error.txt new file mode 100644 index 000000000000..3f7d5f132581 --- /dev/null +++ b/ChangeLog.d/fix-module-import-in-extern-c-compiler-error.txt @@ -0,0 +1,5 @@ +Changes + * Fixes a compiler error when building C++ projects that use the 'modules' + C++ language feature, and consume Mbed TLS. The specific error is + module-import-in-extern-c, which occurs when an #include occurs within + 'extern C' blocks. diff --git a/include/mbedtls/timing.h b/include/mbedtls/timing.h index 62ae1022d91d..0ec7d0821ed0 100644 --- a/include/mbedtls/timing.h +++ b/include/mbedtls/timing.h @@ -15,10 +15,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #if !defined(MBEDTLS_TIMING_ALT) // Regular implementation // @@ -43,6 +39,10 @@ typedef struct mbedtls_timing_delay_context { #include "timing_alt.h" #endif /* MBEDTLS_TIMING_ALT */ +#ifdef __cplusplus +extern "C" { +#endif + /* Internal use */ unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset); diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 8a5d6ba822f0..58f81ed02b0e 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -25,6 +25,7 @@ if(TEST_CPP) ) add_executable(cpp_dummy_build "${cpp_dummy_build_cpp}") set_base_compile_options(cpp_dummy_build) + target_compile_options(cpp_dummy_build PRIVATE -fmodules) target_include_directories(cpp_dummy_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/include