I just ran into an issue with the RW612 SDK for MCUXpresso (v2.16.1). Currently using the MCUX IDE, but this also affects VS CODE.
TL;DR - When compiling a C API module for C++, the extern "C" { } declaration in the header file must surround ALL header file declarations, not just function declarations; otherwise, enum labels defined within structs will not appear in the global namespace as intended.
My issue... I'm writing a C++ driver for the RW612 FLEXCOMM UART, so naturally I'm calling the FSL driver API for the UART and the clock subsystem. Here's my code snippet for attaching the FRG clock:
Source code, compile fails because of C++ namespace issue
But when I compile this, I get an error "'kCLOCK_FrgPllDiv' was not declared in this scope". Well, that's strange, I can see the definition for kCLOCK_FrgPllDiv in fsl_clock.h.
Definition of kCLOCK_FrgPllDiv
Then I realized... I wonder if this is a namespace thing. Turns out, yes it is, because the extern "C" { } declaration is improperly placed. It's only surrounding the C functions in fsl_clock.h; it is NOT surrounding any of the data type declarations in fsl_clock.h, including the definition of clock_frg_clk_config_t.
In C, all enum labels are in the global namespace, even if they are defined within a structure (such as here). In C++, any data type or label defined within a struct, even a "weak" enum label, is scoped by the name of the struct and requires x::y syntax to use. In order to get my code fragment above to compile correctly, I have to write:
"Fixed" code using struct type name::enum label
This is not correct behavior for a native C code module. Moving the extern "C" opening declaration to near the start of the header file (say, line 18) will have no side effects for C code and in C++ will cause all enum labels to appear in the global namespace as intended, regardless of where they are defined.
fsl_clock.h is the only header file currently giving me this issue, but I can see in other FSL header files that the extern "C" { } block is similarly positioned (fsl_flexcomm.h, fsl_gdma.h, etc). You need to fix all of these header files and update your coding standards documentation to prevent this specific issue occurring in the future.
Dana M.