Skip to content

Explicitly set -std=gnu99 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. #1480

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Grinkers
Copy link

@Grinkers Grinkers commented Apr 25, 2025

https://lwn.net/ml/all/aAtlfgZQyPsfBPKA@tucnak/
The C frontend now defaults to the GNU C23 dialect.

With the latest GCC, when using bundled and static-link features, gcc tries to compile with c23 which results in a build failure due to SDL2 using reserved keywords here
https://github.com/libsdl-org/SDL/blob/07d0f51fa292895443f563f0cbde4cb3802d87fa/src/joystick/hidapi/SDL_hidapi_steam.c#L40-L44

Here's the error log for cargo build --features bundled,static-link

  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:42:5: error: cannot use keyword 'false' as enumeration constant
     42 |     false,
        |     ^~~~~
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:42:5: note: 'false' is a keyword with '-std=c23' onwards
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:44:3: error: expected ';', identifier or '(' before 'bool'
     44 | } bool;
        |   ^~~~
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:44:3: warning: useless type name in empty declaration
  gmake[2]: *** [CMakeFiles/SDL2-static.dir/build.make:3067: CMakeFiles/SDL2-static.dir/src/joystick/hidapi/SDL_hidapi_steam.c.o] Error 1
  gmake[2]: *** Waiting for unfinished jobs....
  gmake[1]: *** [CMakeFiles/Makefile2:159: CMakeFiles/SDL2-static.dir/all] Error 2
  gmake: *** [Makefile:136: all] Error 2

  thread 'main' panicked at /home/grinkers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:

  command did not execute successfully, got: exit status: 2

  build script failed, must exit now

@Grinkers Grinkers changed the title Explicitly set -std=gnu17 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. Explicitly set -std=gnu99 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. Apr 25, 2025
@Grinkers
Copy link
Author

Original PR was -std=gnu17, but I realized this could be a very breaking change for people on old systems. I changed it to gnu99.

https://github.com/Grinkers/rust-sdl2/actions/runs/14670059227/job/41174276590
It seems to be working fine on at least CI and gcc15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant