This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Windows dllexport and ISO C binding


2009/2/24 Daniel Kraft <d@domob.eu>:
> Hi all,
>
> I've just received comments from Arjen about ISO C binding. ?He tried to use
> an experimental MySQL binding I wrote which works fine for me on Windows XP.
> ?His report:
>
> I am experimenting with your MySQL bindings, but I get
> some problems (Windows XP):
> - The MySQL embedded library uses the
> __declspec(dllexport)
> ?convention, which means that names are decorated with
> ?@4, @32 etc.
> - If I add these decorations to the names, gfortran
> ?complains these are not valid C names (and quite
> ?correctly so).
> - But it also seems to forget about ISO_C_BINDING then.
>
> Here is a sample:
>
> ? ? ? ?gfortran -c mysql.f90
> mysql.f90:56.29:
>
> ? ?BIND(C, NAME='mysql_error@4')
> ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
> Error: Invalid C name in NAME= specifier at (1)
> mysql.f90:57.23:
>
> ? ? ?USE ISO_C_BINDING
> ? ? ? ? ? ? ? ? ? ? ?1
> Error: Unexpected USE statement in INTERFACE block at (1)
> mysql.f90:58.19:
>
> ? ? ?IMPLICIT NONE
> ? ? ? ? ? ? ? ? ?1
> Error: Unexpected IMPLICIT NONE statement in INTERFACE
> block at (1)
> mysql.f90:59.28:
>
> ? ? ?TYPE(C_PTR) :: c_error
>
> The version of gfortran I am using is:
>
> GNU Fortran (4.3.2-tdm-1 for MinGW) 4.3.2
>

When I compile this snippet

module mysql
use iso_c_binding
contains
subroutine foo() BIND(C, name = "foo@32")
type(c_ptr) :: x
end subroutine foo
end module mysql

it nags at me

$ gfortran -c mysql.F90
mysql.F90:6.36:

subroutine foo() BIND(C, name = "foo@32")
                                   1
Error: Invalid C name in NAME= specifier at (1)
mysql.F90:7.16:

type(c_ptr) :: x
               1
Error: Unexpected data declaration statement in CONTAINS section at (1)
mysql.F90:8.3:

end subroutine foo
  1
Error: Expecting END MODULE statement at (1)

i.e. it ignores the subroutine declaration, and so carries on parsing
the rest of it outside the subroutine's scope. So gfortran does not in
fact forget about ISO_C_BINDING, it just complains about this being
the wrong place to USE it.

Also, dlltool can --kill-at and --add-stdcall-alias, but none of this
claims to change the actual calling convention...

Dennis


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]