riscv-mcu / GD32VF103_Firmware_Library

Original GD32VF103 Firmware Library
128 stars 37 forks source link

gd32vf103.h header cannot be used from C++ module #1

Closed smuehlst closed 1 year ago

smuehlst commented 4 years ago

I'm trying to use the gd32vf103.h header from a C++ module in a PlatformIO project for the Sipeed Longan Nano.

The C++ compilation fails with the following error message:

In file included from C:\.platformio\packages\framework-gd32vf103-sdk\GD32VF103_standard_peripheral\Include/gd32vf103_adc.h:38,
                 from include/gd32vf103_libopt.h:38,
                 from include/gd32v_pjt_include.h:4,
                 from src\main.cpp:35:
C:\.platformio\packages\framework-gd32vf103-sdk\GD32VF103_standard_peripheral/gd32vf103.h:179:41: error: redeclaration of C++ built-in type 
'bool' [-fpermissive]
  179 | typedef enum {FALSE = 0, TRUE = !FALSE} bool;
      |                                         ^~~~

The gd32vf103.h header has some preparations for C++ compilation, but the typedef for bool is not guarded:

https://github.com/riscv-mcu/GD32VF103_Firmware_Library/blob/12b61d1bf29afbee8ec4eee81cdbf1bd9f89470a/Firmware/GD32VF103_standard_peripheral/gd32vf103.h#L179

Are the framework headers intended to be usable from C++?

fanghuaqi commented 4 years ago

@smuehlst You can refer this pull request https://github.com/riscv-mcu/GD32VF103_Firmware_Library/pull/3

smuehlst commented 4 years ago

@fanghuaqi Thanks for the hint, I will use that pull request as a workaround for the time being.

richardclli commented 2 years ago

There are some more problems in other files that used #ifdef cplusplus, I think the correct one should be #ifdef __cplusplus

vazhnov commented 1 year ago

@fanghuaqi, could you please merge the fix into the main branch?

fanghuaqi commented 1 year ago

done