Since this is the header file, your C branch should use extern
as well:
#ifdef __cplusplus
extern "C" MyStruct my_struct;
#else
extern MyStruct my_struct;
#endif
Otherwise, you will end up with multiple definitions of the my_struct
in every translation unit where the header is included, resulting in errors during the linking phase.
The definition of my_struct
should reside in a separate translation unit - either a C file or a CPP file. The header needs to be included as well, to make sure that you get proper linkage.