creating dll to link with delphi program
Brad Finney
brad.finney@humboldt.edu
Sun Oct 23 20:17:00 GMT 2011
On 10/23/2011 12:33 PM, Steve Kargl wrote:
> On Sun, Oct 23, 2011 at 11:57:32AM -0700, Brad Finney wrote:
>>>
>>> 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.
>>>
>>
>> Yes, I did try his suggestion, but missed the addition of the bind(c,
>> name= " "). Thanks for getting me to read more carefully! That does
>> correct the case issue, but not (for me) the underscore issue, which is
>> very puzzling. I took the exact code you listed and got a leading
>> underscore on Foo and bar.
>
> I don't do Windows, so my code did not include
>
> !GCC$ ATTRIBUTES DLLEXPORT::Foo
I had already tried adding those, but it made no difference.
>
>
>> F:\FlowReader>gfortran -shared -o foo.dll foo.o
>> Cannot export Foo: symbol not found
>> Cannot export bar_: symbol not found
>> collect2.exe: error: ld returned 1 exit status
>>
>> F:\FlowReader>gfortran -shared -fno-leading-underscore -o foo.dll foo.o
>> Cannot export Foo: symbol not found
>> Cannot export bar_: symbol not found
>> collect2.exe: error: ld returned 1 exit status
>
> These are loader errors. I'm not familiar with how the loader
> on Windows works. As Tobias noted, you might need to add the
> stdcall attribute, but I thought that only dealt with who was
> responsible for cleaning up the call stack.
>
I had also tried adding stdcall. No difference.
I can actually solve the symbol not found problem by passing the
no-leading-underscore directly to the linker
F:\FlowReader>gfortran -fno-leading-underscore -c foo.f90
F:\FlowReader>gfortran -shared -Xlinker --no-leading-underscore -o
foo.dll foo.o
however if I add a write statement to the subroutine
subroutine foo(n) bind(c, name="Foo")
use iso_c_binding
!GCC$ ATTRIBUTES DLLEXPORT::Foo
integer(c_int) :: n
n = n + n
write(*,*)n
end subroutine foo
and repeat the above compilation and link commands I get undefined
refererces to library routines
F:\FlowReader>gfortran -fno-leading-underscore -c foo.f90
F:\FlowReader>gfortran -shared -Xlinker --no-leading-underscore -o
foo.dll foo.o
foo.o:foo.f90:(.text+0x4c): undefined reference to `_gfortran_st_write'
foo.o:foo.f90:(.text+0x69): undefined reference to
`_gfortran_transfer_integer_write'
foo.o:foo.f90:(.text+0x77): undefined reference to `_gfortran_st_write_done'
collect2.exe: error: ld returned 1 exit status
Very strange and frustrating....
More information about the Fortran
mailing list