<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I think the original program in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138234#M136335</link>
    <description>&lt;P&gt;I think the original program shouldn't compile. The binding label is just a name visible to the linker or in a *.DLL and isn't syntactically the same as the name of a function. You could use it in a Fortran program by explicitly linking to it (XXX in my example) or using LoadLibrary, GetProcAddress, and C_F_PROCPOINTER (YYY in my example, that I can't seem to get to work just now), but there is no way to just invoke it as a function.&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
    use Square_mod, only: getSquare
    use IFWIN, only: LoadLibrary, HANDLE, GetProcAddress
    use ISO_C_BINDING, only: C_FUNPTR, C_F_PROCPOINTER
    implicit none
    procedure(getSquare), bind(C,name='getSq') :: XXX
    integer(HANDLE) hModule
    type(C_FUNPTR) :: ProcAddress
    procedure(getSquare), pointer :: YYY
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", XXX(val)
    hModule = LoadLibrary('Square.dll'//achar(0))
    ProcAddress = transfer(GetProcAddress(hModule,'getSq'//achar(0)),ProcAddress)
    call C_F_PROCPOINTER(ProcAddress,YYY)
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", YYY(val)
end program Square_prog
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 03:37:48 GMT</pubDate>
    <dc:creator>JVanB</dc:creator>
    <dc:date>2019-08-05T03:37:48Z</dc:date>
    <item>
      <title>DLL export with bind C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138231#M136332</link>
      <description>&lt;P&gt;Dear Fortranners, consider the following function,&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;module Square_mod
    implicit none
contains
    function getSquare(val) result(valSquared) bind(C, name="getSquare")
        !DEC$ ATTRIBUTES DLLEXPORT :: getSquare
        use iso_c_binding
        use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
        valSquared = val ** 2
    end function getSquare
end module Square_mod
&lt;/PRE&gt;

&lt;P&gt;Now generating the DLL,&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;ifort /dll Square_mod.f90 /exe:Square&lt;/PRE&gt;

&lt;P&gt;and here is a program that can successfully call the function in the DLL,&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
    use Square_mod, only: getSquare
    implicit none
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", getSquare(val)
end program Square_prog
&lt;/PRE&gt;

&lt;P&gt;However, consider the following modified module that gives its function a different bind(c) name, getSq,&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module Square_mod
    implicit none
contains
    function getSquare(val) result(valSquared) bind(C, name="getSq")
        !DEC$ ATTRIBUTES DLLEXPORT :: getSquare
        use iso_c_binding
        use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
        valSquared = val ** 2
    end function getSquare
end module Square_mod
&lt;/PRE&gt;

&lt;P&gt;Note that the only difference with the original function is in the binding name. I expected this function to be callable with the new name from the main program, but it is not,&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
    use Square_mod, only: getSq
    implicit none
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", getSq(val)
end program Square_prog&lt;/PRE&gt;

&lt;P&gt;Why is ifort able to "use Square_mod, only: getSquare" in the first version with a binding name that is the same as the function name, while in the latter case with a binding name different from the function name, it gives the following compile error?&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;Square_prog.f90(3): error #6580: Name in only-list does not exist or is not accessible.   [GETSQ]
    use Square_mod, only: getSq
--------------------------^
Square_prog.f90(6): error #6404: This name does not have a type, and must have an explicit type.   [GETSQ]
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", getSq(val)
--------------------------------------------------------^
compilation aborted for Square_prog.f90 (code 1)&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 01:15:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138231#M136332</guid>
      <dc:creator>DataScientist</dc:creator>
      <dc:date>2019-08-05T01:15:26Z</dc:date>
    </item>
    <item>
      <title>I think I have got a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138232#M136333</link>
      <description>&lt;P&gt;I think I have got a reasonable understanding of the issue here. The following code, nicely compiles and runs,&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
    use Square_mod, only: getSquare
    implicit none
    real(RK) :: val = 100._RK
    interface
    function getSq(val) result(valSquared)
        !DEC$ ATTRIBUTES DLLIMPORT, DECORATE, ALIAS: 'getSq' :: getSq
        use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
    end function getSq
    end interface
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", getSquare(val)
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", getSq(val)
end program Square_prog
&lt;/PRE&gt;

&lt;P&gt;with the following module compiled to a DLL file that is used by the above program,&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;module Square_mod
    implicit none
contains
    function getSquare(val) result(valSquared) bind(C, name="getSq")
        !DEC$ ATTRIBUTES DLLEXPORT :: getSquare
        use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
        valSquared = val ** 2
    end function getSquare
end module Square_mod&lt;/PRE&gt;

&lt;P&gt;So it seems like, when the bind name (getSq) and the DLLEXPORT (getSquare) name are different, both of them are exported, one as a module procedure which can be "USE"d in Fortran program, and the other as a global identifier "getSq" which can be called by other languages as well as Fortran, as done in the above example program.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 02:59:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138232#M136333</guid>
      <dc:creator>DataScientist</dc:creator>
      <dc:date>2019-08-05T02:59:55Z</dc:date>
    </item>
    <item>
      <title>I'd say that was a compiler</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138233#M136334</link>
      <description>&lt;P&gt;&lt;S&gt;I'd say that was a compiler bug. As you found, the ALIAS attribute works;&amp;nbsp;BIND(C, NAME=) should work the same. Please submit a bug report to Intel Support.&lt;/S&gt; Ignore - see below.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 03:09:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138233#M136334</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-05T03:09:00Z</dc:date>
    </item>
    <item>
      <title>I think the original program</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138234#M136335</link>
      <description>&lt;P&gt;I think the original program shouldn't compile. The binding label is just a name visible to the linker or in a *.DLL and isn't syntactically the same as the name of a function. You could use it in a Fortran program by explicitly linking to it (XXX in my example) or using LoadLibrary, GetProcAddress, and C_F_PROCPOINTER (YYY in my example, that I can't seem to get to work just now), but there is no way to just invoke it as a function.&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK =&amp;gt; real64
    use Square_mod, only: getSquare
    use IFWIN, only: LoadLibrary, HANDLE, GetProcAddress
    use ISO_C_BINDING, only: C_FUNPTR, C_F_PROCPOINTER
    implicit none
    procedure(getSquare), bind(C,name='getSq') :: XXX
    integer(HANDLE) hModule
    type(C_FUNPTR) :: ProcAddress
    procedure(getSquare), pointer :: YYY
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", XXX(val)
    hModule = LoadLibrary('Square.dll'//achar(0))
    ProcAddress = transfer(GetProcAddress(hModule,'getSq'//achar(0)),ProcAddress)
    call C_F_PROCPOINTER(ProcAddress,YYY)
    write(*,"(*(g0.13,:,' '))") "Square of", val, "is", YYY(val)
end program Square_prog
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 03:37:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138234#M136335</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2019-08-05T03:37:48Z</dc:date>
    </item>
    <item>
      <title>Thanks Repeat Offender, very</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138235#M136336</link>
      <description>&lt;P&gt;Thanks Repeat Offender, very interesting third approach, that I had no idea about. Any resources to learn more about IFWIN module would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Steve, thanks. Which implementation is a bug in your opinion? original, or the alternative using `getSq` as the bind name, or the last solution in my response to the question (via DLLIMPORT)?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 05:05:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138235#M136336</guid>
      <dc:creator>DataScientist</dc:creator>
      <dc:date>2019-08-05T05:05:09Z</dc:date>
    </item>
    <item>
      <title>Sorry, I missed something</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138236#M136337</link>
      <description>&lt;P&gt;Sorry, I missed something again.&lt;/P&gt;&lt;P&gt;The original program shows correct behavior. As RO correctly says, you are not supposed to use the binding label for a reference in Fortran. getSq is not a Fortran identifier defined by the module. The compiler correctly DLLEXPORTs 'getSq' as the global symbol and correctly references it when you call getSquare in the main program. There is no compiler bug.&lt;/P&gt;&lt;P&gt;Your revised program that "works" basically does an end-run around the module interface. You should never have to declare an explicit interface to a Fortran routine (generics and submodules sometimes excepted.)&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 05:33:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DLL-export-with-bind-C/m-p/1138236#M136337</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-08-05T05:33:44Z</dc:date>
    </item>
  </channel>
</rss>

