Skip to content

iso_c_binding should be used with only #23

Closed

Description

@foxtran

LLVM flang already contains not-yet-standardized unsigned types, so, compilation of https://github.com/interkosmos/fortran-sdl2/blob/c46f9ac46fc0bd834ea8bdac63df33bf8e727f66/src/c_util.f90 fails with a lot of errors.

Better approach would be to specify, which variables should be extracted from iso_c_binding.

Corresponding bug report in LLVM: llvm/llvm-project#159989

Activity

  1. interkosmos commented on Sep 22, 2025

    @interkosmos
    Owner

    A preprocessor macro has been added with the latest commit for Flang compatiblity. Thank you for reporting.

  2. foxtran commented on Sep 23, 2025

    @foxtran
    ContributorAuthor

    In my opinion, the patch is a bit dangerous since it introduces C preprocessor and loads everything from iso_c_binding. Next time you will need to update it once more.

  3. interkosmos commented on Sep 23, 2025

    @interkosmos
    Owner

    I agree, but see it as a temporary hack on the road to Fortran 2023. Loading the whole iso_c_binding module feels acceptable performance-wise, the module it is imported into is private anyway.

  4. angelog0 commented on Sep 23, 2025

    @angelog0

    Maybe we need now instructions on how to build it because the repo does not build with gfortran any more. gfortran is

    $ gfortran -v
    Using built-in specs.
    COLLECT_GCC=C:\msys64\ucrt64\bin\gfortran.exe
    COLLECT_LTO_WRAPPER=C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/lto-wrapper.exe
    Target: x86_64-w64-mingw32
    Configured with: ../gcc-15.2.0/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-mingw-wildcard --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='Rev8, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-libstdcxx-zoneinfo=yes --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
    Thread model: posix
    Supported LTO compression algorithms: zlib zstd
    gcc version 15.2.0 (Rev8, Built by MSYS2 project)
    

    ...and this as it fails (the make command is how I have always used it)

    $ make FFLAGS='-std=f2018 $(SDL_CFLAGS) -O3' all example
    gfortran -std=f2018  -O3 -fPIC -c src/c_util.F90  src/sdl2/sdl2_stdinc.f90  src/sdl2/sdl2_audio.f90  src/sdl2/sdl2_blendmode.f90  src/sdl2/sdl2_cpuinfo.f90  src/sdl2/sdl2_gamecontroller.f90  src/sdl2/sdl2_error.f90  src/sdl2/sdl2_events.f90  src/sdl2/sdl2_filesystem.f90  src/sdl2/sdl2_hints.f90  src/sdl2/sdl2_joystick.f90  src/sdl2/sdl2_keyboard.f90  src/sdl2/sdl2_log.f90  src/sdl2/sdl2_messagebox.f90  src/sdl2/sdl2_rect.f90  src/sdl2/sdl2_pixels.f90  src/sdl2/sdl2_platform.f90  src/sdl2/sdl2_scancode.f90  src/sdl2/sdl2_surface.f90  src/sdl2/sdl2_render.f90  src/sdl2/sdl2_keycode.f90  src/sdl2/sdl2_mouse.f90  src/sdl2/sdl2_rwops.f90  src/sdl2/sdl2_thread.f90  src/sdl2/sdl2_timer.f90  src/sdl2/sdl2_version.f90  src/sdl2/sdl2_video.f90  src/sdl2/sdl2_opengl.f90  src/sdl2.f90
    src/c_util.F90:16:24:
    
       16 |     public :: c_uint16_t
          |                        1
    Error: Symbol 'c_uint16_t' at (1) has no IMPLICIT type; did you mean 'c_int16_t'?
    src/c_util.F90:17:24:
    
       17 |     public :: c_uint32_t
          |                        1
    Error: Symbol 'c_uint32_t' at (1) has no IMPLICIT type; did you mean 'c_int32_t'?
    src/c_util.F90:18:24:
    
       18 |     public :: c_uint64_t
          |                        1
    Error: Symbol 'c_uint64_t' at (1) has no IMPLICIT type; did you mean 'c_int64_t'?
    src/c_util.F90:15:23:
    
       15 |     public :: c_uint8_t
          |                       1
    Error: Symbol 'c_uint8_t' at (1) has no IMPLICIT type; did you mean 'c_int8_t'?
    src/c_util.F90:19:24:
    
       19 |     public :: c_unsigned
          |                        1
    Error: Symbol 'c_unsigned' at (1) has no IMPLICIT type; did you mean 'c_associated'?
    src/c_util.F90:20:29:
    
       20 |     public :: c_unsigned_char
          |                             1
    Error: Symbol 'c_unsigned_char' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/c_util.F90:21:29:
    
       21 |     public :: c_unsigned_long
          |                             1
    Error: Symbol 'c_unsigned_long' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/c_util.F90:22:34:
    
       22 |     public :: c_unsigned_long_long
          |                                  1
    Error: Symbol 'c_unsigned_long_long' at (1) has no IMPLICIT type; did you mean 'c_long_long'?
    src/c_util.F90:23:30:
    
       23 |     public :: c_unsigned_short
          |                              1
    Error: Symbol 'c_unsigned_short' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/sdl2/sdl2_events.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_log.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_messagebox.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_pixels.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_surface.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_render.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_mouse.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_timer.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t, c_uint64_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_version.f90:10:11:
    
       10 |     use :: c_util, only: c_uint8_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_video.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2.f90:11:11:
    
       11 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    make: *** [Makefile:75: libsdl2.a] Error 1
    
  5. interkosmos commented on Sep 23, 2025

    @interkosmos
    Owner

    Using GNU Fortran 14.2:

    $ gfortran -v
    Using built-in specs.
    COLLECT_GCC=gfortran
    COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc14/gcc/x86_64-portbld-freebsd14.2/14.2.0/lto-wrapper
    Target: x86_64-portbld-freebsd14.2
    Configured with: /tmp/ports/usr/ports/lang/gcc14/work/gcc-14.2.0/configure --without-isl --enable-multilib --with-build-config=bootstrap-debug --disable-nls --disable-libssp --enable-gnu-indirect-function --enable-host-shared --enable-plugin --libdir=/usr/local/lib/gcc14 --libexecdir=/usr/local/libexec/gcc14 --program-suffix=14 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc14/include/c++/ --with-gxx-libcxx-include-dir=/usr/include/c++/v1 --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --enable-languages=c,c++,objc,fortran,jit --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/share/man --infodir=/usr/local/share/info/gcc14 --build=x86_64-portbld-freebsd14.2
    Thread model: posix
    Supported LTO compression algorithms: zlib
    gcc version 14.2.0 (FreeBSD Ports Collection)
    

    Builds just fine:

    $ make FFLAGS="-std=f2018 `sdl2-config --cflags` -O3" all examples
    

    The variable SDL_CFLAGS has been removed from the Makefile in master.

    Edit: According to the GCC documentation, the unsigned constants are supported since GNU Fortran 15.1.

  6. foxtran commented on Sep 23, 2025

    @foxtran
    ContributorAuthor

    the unsigned constants are supported since GNU Fortran 15.1.

    Only if -funsigned is passed.

  7. interkosmos commented on Sep 23, 2025

    @interkosmos
    Owner

    Only if -funsigned is passed.

    That makes portability more cumbersome than expected.

  8. angelog0 commented on Sep 23, 2025

    @angelog0

    Here it fails. For example:

    $ make FFLAGS="-std=f2018 `sdl2-config --cflags` -O3" all examples
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/c_util.F90  src/sdl2/sdl2_stdinc.f90  src/sdl2/sdl2_audio.f90  src/sdl2/sdl2_blendmode.f90  src/sdl2/sdl2_cpuinfo.f90  src/sdl2/sdl2_gamecontroller.f90  src/sdl2/sdl2_error.f90  src/sdl2/sdl2_events.f90  src/sdl2/sdl2_filesystem.f90  src/sdl2/sdl2_hints.f90  src/sdl2/sdl2_joystick.f90  src/sdl2/sdl2_keyboard.f90  src/sdl2/sdl2_log.f90  src/sdl2/sdl2_messagebox.f90  src/sdl2/sdl2_rect.f90  src/sdl2/sdl2_pixels.f90  src/sdl2/sdl2_platform.f90  src/sdl2/sdl2_scancode.f90  src/sdl2/sdl2_surface.f90  src/sdl2/sdl2_render.f90  src/sdl2/sdl2_keycode.f90  src/sdl2/sdl2_mouse.f90  src/sdl2/sdl2_rwops.f90  src/sdl2/sdl2_thread.f90  src/sdl2/sdl2_timer.f90  src/sdl2/sdl2_version.f90  src/sdl2/sdl2_video.f90  src/sdl2/sdl2_opengl.f90  src/sdl2.f90
    src/c_util.F90:16:24:
    
       16 |     public :: c_uint16_t
          |                        1
    Error: Symbol 'c_uint16_t' at (1) has no IMPLICIT type; did you mean 'c_int16_t'?
    src/c_util.F90:17:24:
    
       17 |     public :: c_uint32_t
          |                        1
    Error: Symbol 'c_uint32_t' at (1) has no IMPLICIT type; did you mean 'c_int32_t'?
    src/c_util.F90:18:24:
    
       18 |     public :: c_uint64_t
          |                        1
    Error: Symbol 'c_uint64_t' at (1) has no IMPLICIT type; did you mean 'c_int64_t'?
    src/c_util.F90:15:23:
    
       15 |     public :: c_uint8_t
          |                       1
    Error: Symbol 'c_uint8_t' at (1) has no IMPLICIT type; did you mean 'c_int8_t'?
    src/c_util.F90:19:24:
    
       19 |     public :: c_unsigned
          |                        1
    Error: Symbol 'c_unsigned' at (1) has no IMPLICIT type; did you mean 'c_associated'?
    src/c_util.F90:20:29:
    
       20 |     public :: c_unsigned_char
          |                             1
    Error: Symbol 'c_unsigned_char' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/c_util.F90:21:29:
    
       21 |     public :: c_unsigned_long
          |                             1
    Error: Symbol 'c_unsigned_long' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/c_util.F90:22:34:
    
       22 |     public :: c_unsigned_long_long
          |                                  1
    Error: Symbol 'c_unsigned_long_long' at (1) has no IMPLICIT type; did you mean 'c_long_long'?
    src/c_util.F90:23:30:
    
       23 |     public :: c_unsigned_short
          |                              1
    Error: Symbol 'c_unsigned_short' at (1) has no IMPLICIT type; did you mean 'c_signed_char'?
    src/sdl2/sdl2_events.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_log.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_messagebox.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_pixels.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_surface.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_render.f90:10:11:
    
       10 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_mouse.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_timer.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t, c_uint64_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_version.f90:10:11:
    
       10 |     use :: c_util, only: c_uint8_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2/sdl2_video.f90:10:11:
    
       10 |     use :: c_util, only: c_uint32_t
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    src/sdl2.f90:11:11:
    
       11 |     use :: c_util
          |           1
    Fatal Error: Cannot open module file 'c_util.mod' for reading at (1): No such file or directory
    compilation terminated.
    make: *** [Makefile:75: libsdl2.a] Error 1
    

    The old repo builds OB:

    $ make LIBGL='-lopengl32' LIBGLU='-lglu32' FFLAGS="-std=f2018 `sdl2-config --cflags` -O3" all examples
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/c_util.f90  src/sdl2/sdl2_stdinc.f90  src/sdl2/sdl2_audio.f90  src/sdl2/sdl2_blendmode.f90  src/sdl2/sdl2_cpuinfo.f90  src/sdl2/sdl2_gamecontroller.f90  src/sdl2/sdl2_error.f90  src/sdl2/sdl2_events.f90  src/sdl2/sdl2_filesystem.f90  src/sdl2/sdl2_hints.f90  src/sdl2/sdl2_joystick.f90  src/sdl2/sdl2_keyboard.f90  src/sdl2/sdl2_log.f90  src/sdl2/sdl2_messagebox.f90  src/sdl2/sdl2_rect.f90  src/sdl2/sdl2_pixels.f90  src/sdl2/sdl2_platform.f90  src/sdl2/sdl2_scancode.f90  src/sdl2/sdl2_surface.f90  src/sdl2/sdl2_render.f90  src/sdl2/sdl2_keycode.f90  src/sdl2/sdl2_mouse.f90  src/sdl2/sdl2_rwops.f90  src/sdl2/sdl2_thread.f90  src/sdl2/sdl2_timer.f90  src/sdl2/sdl2_version.f90  src/sdl2/sdl2_video.f90  src/sdl2/sdl2_opengl.f90  src/sdl2.f90
    ar rcs libsdl2.a sdl2.o
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/sdl2_image.f90
    ar rcs libsdl2_image.a sdl2_image.o
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/c_util.f90  src/sdl2_mixer.f90
    ar rcs libsdl2_mixer.a sdl2_mixer.o
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/sdl2_ttf.f90
    ar rcs libsdl2_ttf.a sdl2_ttf.o
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/glu.f90
    ar rcs libglu.a glu.o
    ar rcs libfortran-sdl2.a sdl2.o sdl2_image.o sdl2_mixer.o sdl2_ttf.o glu.o
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o alpha examples/alpha.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o cyclic examples/cyclic.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o draw examples/draw.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o dvd examples/dvd.f90 libsdl2.a libsdl2_image.a `sdl2-config --libs` -lSDL2_image
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o events examples/events.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o fire examples/fire.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o forest examples/forest.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o gl examples/gl.f90 libsdl2.a `sdl2-config --libs` -lopengl32
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o gl3d examples/gl3d.f90 libsdl2.a libsdl2_image.a libglu.a `sdl2-config --libs` -lSDL2_image -lopengl32 -lglu32
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o glsphere examples/glsphere.f90 libsdl2.a libglu.a `sdl2-config --libs` -lopengl32 -lglu32
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o info examples/info.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o log examples/log.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o logo examples/logo.f90 libsdl2.a libsdl2_image.a `sdl2-config --libs` -lSDL2_image
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o image examples/image.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o msgbox examples/msgbox.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o opera examples/opera.f90 libsdl2.a libsdl2_mixer.a libsdl2_ttf.a `sdl2-config --libs` -lSDL2_mixer -lSDL2_ttf
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o pixel examples/pixel.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o scaling examples/scaling.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o text examples/text.f90 libsdl2.a libsdl2_ttf.a `sdl2-config --libs` -lSDL2_ttf
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o vertex examples/vertex.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o voxel examples/voxel.f90 libsdl2.a `sdl2-config --libs`
    gfortran -std=f2018 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -o window examples/window.f90 libsdl2.a `sdl2-config --libs`
    

    Using flang with the new repo segment faults

  9. interkosmos commented on Sep 24, 2025

    @interkosmos
    Owner

    The unsigned argument has to be passed to GNU Fortran 15:

    $ make all FFLAGS="-funsigned `sdl2-config --cflags`"
    

    I’ve made some changes to the c_util module, it should be compatible to gfortran 14 and 15 now.

  10. angelog0 commented on Sep 24, 2025

    @angelog0

    The unsigned argument has to be passed to GNU Fortran 15:

    I tested the following.

    It build but emits a lot of warnings and, sincerely, all these changes look workarounds and not a clean solution. Before the changes for flang support, the old repo builds OB without warnings and without -funsigned with GFortran 15. In any case, flang is not supported because it segments faults as I wrote here

    $ make LIBGL='-lopengl32' LIBGLU='-lglu32' FFLAGS="-funsigned -Wall -std=f2018 -fmax-errors=1 `sdl2-config --cflags` -O3
    " all examples
    gfortran -funsigned -Wall -std=f2018 -fmax-errors=1 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/c_util.F90  src/sdl2/sdl2_stdinc.f90  src/sdl2/sdl2_audio.f90  src/sdl2/sdl2_blendmode.f90  src/sdl2/sdl2_cpuinfo.f90  src/sdl2/sdl2_gamecontroller.f90  src/sdl2/sdl2_error.f90  src/sdl2/sdl2_events.f90  src/sdl2/sdl2_filesystem.f90  src/sdl2/sdl2_hints.f90  src/sdl2/sdl2_joystick.f90  src/sdl2/sdl2_keyboard.f90  src/sdl2/sdl2_log.f90  src/sdl2/sdl2_messagebox.f90  src/sdl2/sdl2_rect.f90  src/sdl2/sdl2_pixels.f90  src/sdl2/sdl2_platform.f90  src/sdl2/sdl2_scancode.f90  src/sdl2/sdl2_surface.f90  src/sdl2/sdl2_render.f90  src/sdl2/sdl2_keycode.f90  src/sdl2/sdl2_mouse.f90  src/sdl2/sdl2_rwops.f90  src/sdl2/sdl2_thread.f90  src/sdl2/sdl2_timer.f90  src/sdl2/sdl2_version.f90  src/sdl2/sdl2_video.f90  src/sdl2/sdl2_opengl.f90  src/sdl2.f90
    src/sdl2/sdl2_events.f90:66:15:
    
       66 |         integer(kind=c_uint32_t) :: type
          |               1
    Warning: C kind type parameter is for type UNSIGNED but type at (1) is INTEGER
    src/sdl2/sdl2_events.f90:67:15:
    
       67 |         integer(kind=c_uint32_t) :: timestamp
          |               1
    Warning: C kind type parameter is for type UNSIGNED but type at (1) is INTEGER
    src/sdl2/sdl2_events.f90:72:15:
    
       72 |         integer(kind=c_uint32_t) :: type
          |               1
    Warning: C kind type parameter is for type UNSIGNED but type at (1) is INTEGER
    src/sdl2/sdl2_events.f90:73:15:
    
    [...]
    
    Warning: C kind type parameter is for type UNSIGNED but type at (1) is INTEGER
    ar rcs libsdl2.a sdl2.o
    gfortran -funsigned -Wall -std=f2018 -fmax-errors=1 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/sdl2_image.f90
    ar rcs libsdl2_image.a sdl2_image.o
    gfortran -funsigned -Wall -std=f2018 -fmax-errors=1 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/c_util.F90  src/sdl2_mixer.f90
    src/sdl2_mixer.f90:90:19:
    
       90 |             integer(kind=c_uint32_t), intent(in), value :: format
          |                   1
    Warning: C kind type parameter is for type UNSIGNED but type at (1) is INTEGER
    ar rcs libsdl2_mixer.a sdl2_mixer.o
    gfortran -funsigned -Wall -std=f2018 -fmax-errors=1 -IC:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main -O3 -fPIC -c src/sdl2_ttf.f90
    
    ....
    
    
  11. angelog0 commented on Sep 24, 2025

    @angelog0

    Just for completeness...

    Applying this patch to old c_utils.f90 , no preprocessing,

    --- src/c_util.f90~     2025-09-21 17:09:15.730119100 +0200
    +++ src/c_util.f90      2025-09-21 22:29:08.599670200 +0200
    @@ -6,7 +6,9 @@
     ! GitHub:  https://github.com/interkosmos/fortran-sdl2/
     ! Licence: ISC
     module c_util
    -    use, intrinsic :: iso_c_binding
    +  use, intrinsic :: iso_c_binding, only: c_int8_t, c_int16_t, c_int32_t, &
    +       c_int64_t, c_int, c_signed_char, c_long, c_long_long, c_short, &
    +       c_ptr, c_size_t
         implicit none
    
         integer, parameter :: c_uint8_t            = c_int8_t
    

    builds OB both with GFortran 15 and Flang 21.

    $ gfortran `sdl2-config --cflags` -O3 -fPIC -c c_util.f90
    
    $ flang `sdl2-config --cflags` -O3 -fPIC -c c_util.f90
    
    

    Instead the new c_utils.f90, with preprocessing,

    $ flang `sdl2-config --cflags` -O3 -fPIC -c src/c_util.f90
    error: Could not scan src/c_util.f90
    ./src/c_util.f90:10:13: error: excess characters after expression
      #if defined (__flang__) || (defined (__GFORTRAN__) && __GNUC__ > 15) || (defined (__GFORTRAN__) && __GNUC__ == 15 && __GNUC_MINOR__ >= 2)
                  ^^^^^^^^^^^
    
    $ gfortran `sdl2-config --cflags` -O3 -fPIC -c src/c_util.f90
    src/c_util.f90:10:2:
    
       10 | #if defined (__flang__) || (defined (__GFORTRAN__) && __GNUC__ > 15) || (defined (__GFORTRAN__) && __GNUC__ == 15 && __GNUC_MINOR__ >= 2)
          |  1
    Warning: Illegal preprocessor directive
    src/c_util.f90:27:2:
    
       27 | #else
          |  1
    Warning: Illegal preprocessor directive
    src/c_util.f90:44:2:
    
       44 | #endif
          |  1
    Warning: Illegal preprocessor directive
    src/c_util.f90:12:89:
    
       12 |     use, intrinsic :: iso_c_binding, only: c_uint8_t, c_uint16_t, c_uint32_t, c_uint64_t, c_unsigned, c_unsigned_char, &
          |                                                                                         1
    Error: The symbol 'c_unsigned', referenced at (1), is not in the selected standard
    src/c_util.f90:13:81:
    
    ...
    

    Maybe you need to avoid preprocessing and patch the files using the use :: only..

  12. toxtran commented on Sep 24, 2025

    @toxtran

    Just add -cpp flag.

  13. angelog0 commented on Sep 24, 2025

    @angelog0

    Just add -cpp flag.

    $ gfortran -cpp `sdl2-config --cflags` -O3 -fPIC -c src/c_util.f90
    src/c_util.f90:12:89:
    
       12 |     use, intrinsic :: iso_c_binding, only: c_uint8_t, c_uint16_t, c_uint32_t, c_uint64_t, c_unsigned, c_unsigned_char, &
          |                                                                                         1
    Error: The symbol 'c_unsigned', referenced at (1), is not in the selected standard
    src/c_util.f90:13:81:
    
       13 |                                            c_unsigned_long, c_unsigned_long_long, c_unsigned_short
          |                                                                                 1
    Error: The symbol 'c_unsigned_short', referenced at (1), is not in the selected standard
    src/c_util.f90:12:101:
    
    ...
    

    with Flang builds: flang -cpp sdl2-config --cflags -O3 -fPIC -c src/c_util.f90

    The command

    make LIBGL='-lopengl32' LIBGLU='-lglu32' FFLAGS="-cpp -funsigned -Wall -std=f2018 -fmax-errors=1 `sdl2-config --cflags` -O3" all examples
    

    produces the same warnings, while

    make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS="-cpp -funsigned -std=f2018 `sdl2-config --cflags` -O3" all examples
    

    produces the same segment fault.

  14. toxtran commented on Sep 24, 2025

    @toxtran

    Ok. It looks strange.. I will have a look at morning.. and probably patch :-)

  15. interkosmos commented on Sep 25, 2025

    @interkosmos
    Owner

    I’m building GCC 15.2 from source now and will investigate further.

  16. foxtran commented on Sep 25, 2025

    @foxtran
    ContributorAuthor

    @interkosmos, see #24

    Morning did not happen today :(

  17. angelog0 commented on Sep 28, 2025

    @angelog0

    I see the repo has been updated today. It builds with GFortran,

    make LIBGL='-lopengl32' LIBGLU='-lglu32' FFLAGS='-Wall -std=f2018 -fmax-errors=1 -O3' all examples
    

    there is just this warning:

    examples/gl3d.f90:201:5:
    
      201 |     subroutine gl_perspective(fovy, aspect, znear, zfar)
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~
    Warning: 'gl_perspective' defined but not used [-Wunused-function]
    

    All examples seems to work, at least they does not segment fault, core dump etc.

    With Flang the repo segment faults as I already flagged. I used these commands to try the build:

    1) make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS='-std=f2018 -O3' all examples
    2) make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS='-DHAS_UNSIGNED -std=f2018 -O3' all examples
    3) make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS='-funsigned -std=f2018 -O3' all examples
    

    All the above on Windows 11, MSYS2/UCRT64, GFortran 15.2.0

  18. angelog0 commented on Sep 28, 2025

    @angelog0

    In the README.md there is written:

    With GNU Fortran ≥ 15.2 you need to additionally pass argument -funsigned
    

    but, as I wrote above, on Windows+MSYS2/UCRT64+GFortran 15.2.0, I do not need it. It just builds with

    make LIBGL='-lopengl32' LIBGLU='-lglu32' FFLAGS='-Wall -std=f2018 -fmax-errors=1 -O3' all examples
    
  19. foxtran commented on Oct 2, 2025

    @foxtran
    ContributorAuthor

    In the README.md there is written:

    Oops. One have to use -funsigned -DHAS_UNSIGNED. Only in that case, unsigned types will be used. The same is for flang.

  20. foxtran commented on Oct 2, 2025

    @foxtran
    ContributorAuthor

    @angelog0, could you please try make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS='-std=f2018 -O3 -g' all examples and see, what causes SegFaults.

  21. angelog0 commented on Oct 2, 2025

    @angelog0

    could you please try make LIBGL='-lopengl32' LIBGLU='-lglu32' FC='flang' FFLAGS='-std=f2018 -O3 -g' all examples and see, what causes SegFaults.

    I already sent what segment fault asked

    I repeat here (just adding -g flag)

    flang.output.gz

    flang_failure.tar.gz

    I can't help any more than that, my mind refuse to use gdb and friends, someone else has to do the work...

  22. foxtran commented on Oct 2, 2025

    @foxtran
    ContributorAuthor

    Ah. Got it. Now, it is definitely a compiler bug.

  23. foxtran commented on Oct 2, 2025

    @foxtran
    ContributorAuthor

    flang@0d92b7f9021e3a0c891db9ffb4eac4fc721981f8 runs given command without errors... But is it for Linux. I do not have an access to Windows for checking.

  24. interkosmos commented on Oct 22, 2025

    @interkosmos
    Owner

    Thank you, seems to be solved for now. Please reopen if there are any persistent issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions