creating dll to link with delphi program

Brad Finney brad.finney@humboldt.edu
Sun Oct 23 18:07:00 GMT 2011



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.

Brad



More information about the Fortran mailing list