Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails with IAR C++ compiler #1344

Closed
alexandre-perrin opened this issue Feb 23, 2022 · 4 comments
Closed

Compilation fails with IAR C++ compiler #1344

alexandre-perrin opened this issue Feb 23, 2022 · 4 comments
Labels

Comments

@alexandre-perrin
Copy link
Contributor

Operating System

Windows 11

Board

Any

Firmware

Compile a simple cpp file including tusb.h

// main.cpp
#include <tusb.h>

int main(void)
{
  return 0;
}

What happened ?

Cpp compiler complains about TU_VERIFY_STATIC with the following errors:

  • this declaration has no storage class or type specifier
  • too many initializer values
  • variable "_Static_assert" has already been defined

How to reproduce ?

Create an empty IAR project with including tinyUSB/src in search paths.
Add provided main.cpp
Try to compile.

Debug Log

 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 303 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 303 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 314 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 314 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 314 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 330 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 330 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 330 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 347 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 347 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 347 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 368 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 368 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 368 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 400 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 400 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 400 
 Error[Pe077]: this declaration has no storage class or type specifier tinyusb\src\common\tusb_types.h 489 
 Error[Pe247]: variable "_Static_assert" has already been defined (at line 303) tinyusb\src\common\tusb_types.h 489 
 Error[Pe146]: too many initializer values tinyusb\src\common\tusb_types.h 489 

Screenshots

No response

@alexandre-perrin
Copy link
Contributor Author

The problem seems to come from IAR that defines __STDC_VERSION__ in cpp as well.
Which causes TU_VERIFY_STATIC to be defined as _Static_assert instead of cpp's static_assert.

A simple fix is to reorder __cplusplus__ to be first, then to fallback to __STDC_VERSION__ if not CPP.

@hathach
Copy link
Owner

hathach commented Feb 23, 2022

would you mind making an PR for this ? Since I don't use IAR at all to verify the result.

@alexandre-perrin
Copy link
Contributor Author

Yes, sure. This is on it's way ;)

@hathach
Copy link
Owner

hathach commented Mar 1, 2022

fixed by #1345

@hathach hathach closed this as completed Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants