fortran - Is this linker error in 32 bit Windows gFortran a bug? -


the following code compiles 64 bit use of fortran generic interfaces seems confuse gcc attribute in 32 bit (required call 32 bit stdcall api). code stripped down version of f03gl project attempting build windows (i couldn't create smaller repro).

a rework of code (shown @ bottom) without generic interface , passing arguments direct compile , work. i'm hoping won't have rewrite of calls work around issue.

the error is;

callglutbad.o:callglutbad.f90:(.text+0x27): undefined reference `glutinit' 

callglut.f90 (fails 32 bit compilation)

module glutmodule   use iso_c_binding   implicit none   public glutinit    interface glutinit     module procedure glutinit_f03   end interface glutinit    interface      subroutine glutinit_gl(pargc, argv) bind(c,name="glutinit")       import  #ifdef x86 !gcc$ attributes stdcall :: glutinit #endif       integer(c_int) :: pargc       type(c_ptr), intent(in) :: argv     end subroutine glutinit_gl    end interface    contains    subroutine glutinit_f03()     integer(c_int) :: argcp=1     type(c_ptr), dimension(1), target :: argv=c_null_ptr     character(c_char), dimension(1), target :: empty_string=c_null_char      argv(1)=c_loc(empty_string)     call glutinit_gl(argcp, c_loc(argv))    end subroutine  end module glutmodule  program main   use glutmodule    print *,"calling glutinit"   call glutinit()   print *,"called glutinit"  end program main 

build.bat

rem 32 bit  @setlocal @set path=%path%;c:\msys64\mingw32\bin\ gfortran -dx86 -cpp -c callglut.f90 -o callglut.o gcc callglut.o -o callglut32.exe ..\x86\lib\freeglut.lib -lgfortran @endlocal  rem 64 bit  @setlocal @set path=%path%;c:\msys64\mingw64\bin\ gfortran -cpp -c callglut.f90 -o callglut.o gcc callglut.o -o callglut64.exe ..\x64\lib\freeglut.lib -lgfortran @endlocal 

the generic interface used call glutinit without parameters fortran (the parameters filled in proxy subroutine).

callglut.f90 (compiles , runs on both platforms)

module glutmodule   use iso_c_binding   implicit none   public glutinit    interface      subroutine glutinit(pargc, argv) bind(c,name="glutinit")       import  #ifdef x86 !gcc$ attributes stdcall :: glutinit #endif       integer(c_int) :: pargc       type(c_ptr), intent(in) :: argv     end subroutine glutinit   end interface  end module glutmodule  program main   use glutmodule    print *,"calling glutinit"   call glutinit(0,c_null_ptr)   print *,"called glutinit"  end program main 

am seeing compiler bug attribute statement not being applied generic interface or doing? suspect , 32 bit stdcall name mangling glutinit _glutinit@8 not being performed.

i using gfortran under msys2 (gnu fortran (rev2, built msys2 project) 7.1.0) on 64 bit windows both 32 , 64 bit compilers.

it doesn't make sense apply stdcall attribute identifier generic name. compiler's perspective, generic name common label number of procedures. while individual specific procedures may have different calling conventions, label them not.

if want tell compiler specific procedure has calling convention, use name compiler knows specific procedure by, in relevant declaration.

!gcc$ attributes stdcall :: glutinit_gl 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -