为什么在使用BIND(C,NAME =" name")属性时不会导出fortran函数 [英] Why aren't my fortran functions exported when using the BIND(C, NAME="name") attribute

查看:1270
本文介绍了为什么在使用BIND(C,NAME =" name")属性时不会导出fortran函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯使用下面的语法:

$ $ $ $ $ $ $ $ $ $ $子程序CalcA(A,N)
!DEC $ ATTRIBUTES DLLEXPORT :: CALCA
!DEC $ ATTRIBUTES ALIAS:'CalcA':: CalcA
IMPLICIT NONE
...
结束子程序CalcA

在.dll中生成导出的函数



现在我正在尝试新的 ISO_C_BINDING 与下面的代码:
$ b $ pre $子程序CalcA(A,N)BIND(C,NAME = CalcA)
USE,INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
...
结束子程序CalcA

但是导出函数没有被创建



那么我在这里错过了什么?新的 iso_c_binding 将如何替换已弃用的!DEC $ ATTRIBUTE DLLEXPORT c $ c>声明?



PS。我正在通过VS2010在Win7-64平台上进行英特尔Fortran XE 2013。

解决方案

正如Hans所建议的,程序不是导出,因为链接器没有被要求导出它。



BIND子句中的绑定标签(ISO_C_BINDING模块与讨论无关)实际上设置了链接器(类似于ATTRIBUTES ALIAS所做的),并且以与C一致的方式进行.BIND子句还将调用约定设置为C兼容(类似于ATTRIBUTES C)。 BIND子句的集体作用还包括ATTRIBUTES DECORATE的集体作用(并且集体编译器指令属性和我没有考虑过的子句之间可能存在其他细微差别)。

至少有三种标记过程的方式,以便将其导出到DLL中:




  • (这是ATTRIBUTES DLLEXPORT如何与ifort协同工作)。
  • 链接时传递给链接器的模块定义文件(.DEF)的EXPORTS部分中的
  • 条目。 / li>
  • 命令将链接参数链接到链接器本身(/ EXPORT:xxx)。 你取决于...有些人喜欢有导出文件的出口,其他人发现编译器指令的视觉外观和非标准性令人难以忍受。


    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.

    解决方案

    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.

    这篇关于为什么在使用BIND(C,NAME =" name")属性时不会导出fortran函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆