suikan4github / rpp_driver

An experimental Duplex I2S implementation on PIO and its example applications.
MIT License
0 stars 0 forks source link

Fails to compile in MSVC. #11

Closed suikan4github closed 1 month ago

suikan4github commented 1 month ago

See the result of the action.

https://github.com/suikan4github/rpp_driver/actions/runs/11283140455/job/31381988605

We have an error message like this :

 D:\a\rpp_driver\rpp_driver\src\sdk\pico_sdk_apistub.cpp(169,1): error C2374: '__attribute__': redefinition; multiple initialization [D:\a\rpp_driver\rpp_driver\build\test\test_rpp_driver.vcxproj]
      D:\a\rpp_driver\rpp_driver\src\sdk\pico_sdk_apistub.cpp(15,1):
      see declaration of '__attribute__'

The weak binding is required only for the pico platform. So, we can skip it by #if #endif.

suikan4github commented 1 month ago

This is the actual implementation.

MSVC also needs weak binding. Otherwise, the test program is unable to compile. On the other hand, MSVC doesn't have weak binding. So, we use alternatename pragma. The alternatename is a kind of alias that works only when the target symbol is unavailable. So, this is weak binding.

The alternatename is the command of the linker. So, we need to think of the symbol as a link phase. In the 32-bit MVS compile, the C symbol will have an extra "" at the head of the symbol. in the 64-bit MSVC compile, there is no extra "".

extern "C" void gpio_put(uint gpio, bool value);
#if defined(__GNUC__) || defined(__clang__)
__attribute__((weak)) void gpio_put(uint gpio, bool value)
#elif defined(_MSVC_VER)
#if defined(_M_IX86)  // MSVC for x86
#pragma comment(linker, "/alternatename:_gpio_put=__weak_gpio_put")
#elif defined(_M_AMD64)  // MSVC for AMD64
#pragma comment(linker, "/alternatename:gpio_put=_weak_gpio_put")
#endif  // _MSVC_VER
void _weak_gpio_put(uint gpio, bool value)
#else
#error "Unknown compiler."
#endif
{
  assert(false &&
         "Error : The hardware_gpio library is missing in the link phase.");
}
suikan4github commented 1 month ago

Fixed. Merged to develop. Ready to release.