Why aren't my fortran functions exported when using the BIND(C, NAME=“name”) attribute

泪湿孤枕 提交于 2019-12-22 22:52:31

问题


I am used to using the following syntax

    subroutine CalcA(A,N)
    !DEC$ ATTRIBUTES DLLEXPORT :: CALCA
    !DEC$ ATTRIBUTES ALIAS:'CalcA' :: CalcA
    IMPLICIT NONE        
    ...
    end subroutine CalcA

which produces an exported function in a .dll

So now I am trying the new ISO_C_BINDING with the following code

    subroutine CalcA(A,N) BIND(C, NAME="CalcA")
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE        
    ...        
    end subroutine CalcA

But the export function is not created

So what am I missing here? How is the new iso_c_binding going to replace the deprecated !DEC$ ATTRIBUTE DLLEXPORT declarations?

PS. I am on Intel Fortran XE 2013 on a Win7-64 platform through VS2010.


回答1:


As Hans suggests, the procedure wasn't exported because the linker wasn't asked to export it.

The binding label in the BIND clause (the ISO_C_BINDING module is not relevant to the discussion) practically sets the "linker name" of the procedure (similar to what ATTRIBUTES ALIAS does) and does so in a manner that is consistent with C. The BIND clause also sets the calling convention to be C compatible (similar to ATTRIBUTES C). The collective effect of the BIND clause also includes that of ATTRIBUTES DECORATE (and there may be other subtle differences between the collective compiler directive attributes and the clause that I've no considered).

There are at least three ways of marking a procedure such that it is exported in a DLL:

  • entries in the object file that holds the procedure (this is how ATTRIBUTES DLLEXPORT works with ifort).
  • entries in the EXPORTS section of a module definition file (.DEF) that is passed to the linker at link time.
  • command link arguments to the linker itself (/EXPORT:xxx).

What's best for you depends... some prefer to have in-source documentation of the export, others find the visual appearance and non-standard nature of compiler directives intolerably odious.



来源:https://stackoverflow.com/questions/20684297/why-arent-my-fortran-functions-exported-when-using-the-bindc-name-name-att

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!