This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: creating dll to link with delphi program
On Sun, Oct 23, 2011 at 11:07:09AM -0700, Brad Finney wrote:
>
>
> On 10/23/2011 7:18 AM, Tobias Burnus wrote:
> >Brad Finney wrote:
> >>SUBROUTINE PrintOutX(x)
> >>!GCC$ ATTRIBUTES DLLEXPORT::PrintOutX
> >>write(*,*)x
> >>END SUBROUTINE PrintOutX
> >>
> >>if I use
> >>gfortran -c -fno-leading-underscore -fno-underscoring testcase.f90
> >>
> >>The object file contains -export:"printoutx" which does not preserve
> >>the case of the requested export name.
> >
> >In gfortran - contrary to ifort -, you have to use C binding, cf.
> >http://gcc.gnu.org/onlinedocs/gfortran/Mixed_002dLanguage-Programming.html
> >
> >SUBROUTINE PrintOutX(x) bind(c, name="PrintOutX")
> >!GCC$ ATTRIBUTES DLLEXPORT::PrintOutX
> >use iso_c_binding
> >real(c_float) x
> >write(*,*) x
> >end
> >
> >
> >That should work without special options. Note: Depending on the caller,
> >you might need to add "stdcall" - but the default "cdecl" could also be
> >correct.
> >
> >Tobias
> >
>
>
> I guess I did not make myself clear enough with my example. The problem
> is not with the argument x, it is with the leading and trailing
> underscores added to the procedure names. If I use
>
> -fno-leading-underscore
>
> then the object code contains references to gfortran library routines
> without the additional underscore and the linker can't resolve those
> references. If I don't use the -fno-leading-underscore option, then my
> procedure names have a leading underscore which the previously compiled
> main program can't find since it is looking for names lacking the
> leading underscore.
>
> What I need is a way to turn off leading (and trailing) underscores for
> my routines but not gfortran library routine names. I am also concerned
> that gfortran does not seem to be preserving the case of the requested
> exported procedure names.
Did you try Tobias's suggestion
laptop:kargl[213] cat foo.f90
subroutine foo(n) bind(c, name="Foo")
use iso_c_binding
integer(c_int) :: n
n = n + n
end subroutine foo
subroutine bar(n)
use iso_c_binding
integer(c_int) :: n
n = n + n
end subroutine bar
laptop:kargl[214] gfc4x -c foo.f90
laptop:kargl[215] nm foo.o
00000000 T Foo
00000016 T bar_
foo and bar are identical except for explicitly namng foo
as Foo in the bind() expression. Note case is preserved and
there is no trailing underscore.
--
Steve