problem with fortran common block in shared library

Marco Atzeri marco.atzeri@gmail.com
Wed Mar 1 18:49:00 GMT 2017


On 06/01/2017 16:52, Bill Greene wrote:
> This problem is not a generic gcc/gfortran one.
> If you build the test code on Linux, it works correctly.
>
> Bill
>

the problem is gfortran one on Windows platform

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47030
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68040

If you create a directive like

--------------------------------------
!GCC$ ATTRIBUTES DLLEXPORT :: /cb1/
       integer cvar
       common /cb1/ cvar
--------------------------------------

It produces and error like
--------------------------------------
  !GCC$ ATTRIBUTES DLLEXPORT :: /cb1/
                                1
Error: Invalid character in name at (1)
--------------------------------------

so the DLLEXPORT directive is not correctly
managing "common" as "/cb1/"

I also noted that the "!GCC$" must be at the beginning of the line
otherwise is totally ignored, that is also very hard to note.

Regards
Marco







-------------- next part --------------
#!/bin/sh -x
cat >cb_main.f <<\EOF
      program cb_main
      !GCC$ ATTRIBUTES DLLEXPORT :: /cb1/
      integer cvar
      common /cb1/ cvar
      cvar = 0
      call cb_func()
      if(cvar.eq.2) then
          write(*,*)'GOOD COMMON BLOCK'
      else
          write(*,*)'BAD COMMON BLOCK'
      endif
      end
EOF
cat >cb_func.f <<\EOF
      subroutine cb_func()
      !GCC$ ATTRIBUTES DLLIMPORT :: /cb1/
      integer cvar
      common /cb1/ cvar
      cvar = 2
      cvar2 = 2
      end
EOF
################################################################################
rm -f *.o *.dll *.a *.exe
gfortran -c cb_func.f 
gfortran -c cb_main.f 
################################################################################
ar cr libcb_static.a cb_func.o
gfortran cb_main.o -L. -lcb_static -o cb_main_static
################################################################################
gfortran -shared -o libcb_dynamic.dll cb_func.o 
gfortran cb_main.o -L. -lcb_dynamic -o cb_main_dynamic 
################################################################################
./cb_main_static
./cb_main_dynamic
################################################################################
-------------- next part --------------
#!/bin/sh -x
cat >cb_main.f <<\EOF
      program cb_main
!GCC$ ATTRIBUTES DLLEXPORT :: /cb1/
      integer cvar
      common /cb1/ cvar
      cvar = 0
      call cb_func()
      if(cvar.eq.2) then
          write(*,*)'GOOD COMMON BLOCK'
      else
          write(*,*)'BAD COMMON BLOCK'
      endif
      end
EOF
cat >cb_func.f <<\EOF
      subroutine cb_func()
!GCC$ ATTRIBUTES DLLIMPORT :: /cb1/
      integer cvar
      common /cb1/ cvar
      cvar = 2
      cvar2 = 2
      end
EOF
################################################################################
rm -f *.o *.dll *.a *.exe
gfortran -c cb_func.f 
gfortran -c cb_main.f 
################################################################################
ar cr libcb_static.a cb_func.o
gfortran cb_main.o -L. -lcb_static -o cb_main_static
################################################################################
gfortran -shared -o libcb_dynamic.dll cb_func.o 
gfortran cb_main.o -L. -lcb_dynamic -o cb_main_dynamic 
################################################################################
./cb_main_static
./cb_main_dynamic
################################################################################
-------------- next part --------------

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list