Gfortran, DLL, underline

I want to access some routines from a third-party DLL. Functions use STDCALL as the calling convention.

Running dumpbin /export foo.dllgives me something like:

      ...
      7    6 00004B40 Foo@16
      ...

I will compile my code using:

      gfortran test.f90 -o test.exe -Wl,foo.dll

I get an error: undefined reference to '_foo_'(pay attention to underscores).

I tried to add a -mrtdcompilation flag , as well as other flags that I googled, all to no avail.

How can I make fortran not add underscores?


edit: A little clarification is in order.

  • I have an existing DLL to which I have no source.
  • This DLL is written in Visual Basic if that helps.
  • I want to name this dll from fortran.
  • When I write to test.f90: Foo(1.0d0)I get an errorundefined reference to '_foo_'
0
4
+3

ISO_C_BINDING . Mixed-Language Programming gfortran. , . , stdcall:

interface VisBasSubs

   subroutine foo (DoubleArg)  bind (C, name="Foo")
      !GCC$ ATTRIBUTES stdcall :: foo
      use iso_c_binding, only: c_double
      real (kind=c_double), intent (inout) :: DoubleArg      

   end subroutine foo

end interface VisBasSubs

stdcall, , .

+2

M.S.B -fno-underscoring answer: f2c g77 . gfortran:

-funderscoring , GNU Fortran . , UNIX Fortran.

: GNU Fortran f2c g77, -ff2c, , , GNU Fortran , .

-fno-underscoring , , GNU Fortran ( , , ..).

, DLL - -fno-underscoring, DLL.

, / Fortran: _prefix suffix_ , ! :

#ifdef LC_UNSC
#define  GET_DIP_MOMENT get_dip_moment_
#elif LC_NOUNSC
#define  GET_DIP_MOMENT get_dip_moment
#endif
...
     call GET_DIP_MOMENT()
+1

ISO C Fortran 2003, gfortran >= 4.3. C (.., , ), Fortran. () , Windows Linker . , Fortran - , .

"" Fortran, "Foo", , Foo C ( void) - / Fortran C. Foo , . "bind" , , . Foo Fortran, "" Fortran.

C - , Visual Basic. ISO C , , , , .

interface VisBasSubs

   subroutine foo (DoubleArg)  bind (C, name="Foo")

      use iso_c_binding, only: c_double
      real (kind=c_double), intent (inout) :: DoubleArg      

   end subroutine foo

end interface VisBasSubs
0

All Articles