Error access violation reading 0x0000000a when call fortran dll made by gfortran原因分析及解决方案

在使用python或VS调用gcc (gfortran)编译的Fortran 动态连接库时,出现Error access violation reading 0x0000000a问题,主要是因为调用约定写错了。

原因分析如下
https://gcc.gnu.org/onlinedocs/gfortran/ATTRIBUTES-directive.html#ATTRIBUTES-directive

7.2.1 ATTRIBUTES directive
The Fortran standard describes how a conforming program shall behave; however, the exact implementation is not standardized. In order to allow the user to choose specific implementation details, compiler directives can be used to set attributes of variables and procedures which are not part of the standard. Whether a given attribute is supported and its exact effects depend on both the operating system and on the processor; see C Extensions in Using the GNU Compiler Collection (GCC) for details.

For procedures and procedure pointers, the following attributes can be used to change the calling convention:

CDECL – standard C calling convention
STDCALL – convention where the called procedure pops the stack
FASTCALL – part of the arguments are passed via registers instead using the stack
Besides changing the calling convention, the attributes also influence the decoration of the symbol name, e.g., by a leading underscore or by a trailing at-sign followed by the number of bytes on the stack. When assigning a procedure to a procedure pointer, both should use the same calling convention.

On some systems, procedures and global variables (module variables and COMMON blocks) need special handling to be accessible when they are in a shared library. The following attributes are available:

DLLEXPORT – provide a global pointer to a pointer in the DLL
DLLIMPORT – reference the function or variable using a global pointer
For dummy arguments, the NO_ARG_CHECK attribute can be used; in other compilers, it is also known as IGNORE_TKR. For dummy arguments with this attribute actual arguments of any type and kind (similar to TYPE()), scalars and arrays of any rank (no equivalent in Fortran standard) are accepted. As with TYPE(), the argument is unlimited polymorphic and no type information is available. Additionally, the argument may only be passed to dummy arguments with the NO_ARG_CHECK attribute and as argument to the PRESENT intrinsic function and to C_LOC of the ISO_C_BINDING module.

Variables with NO_ARG_CHECK attribute shall be of assumed-type (TYPE(); recommended) or of type INTEGER, LOGICAL, REAL or COMPLEX. They shall not have the ALLOCATE, CODIMENSION, INTENT(OUT), POINTER or VALUE attribute; furthermore, they shall be either scalar or of assumed-size (dimension()). As TYPE(*), the NO_ARG_CHECK attribute requires an explicit interface.

NO_ARG_CHECK – disable the type, kind and rank checking
DEPRECATED – print a warning when using a such-tagged deprecated procedure, variable or parameter; the warning can be suppressed with -Wno-deprecated-declarations.
The attributes are specified using the syntax

!GCC$ ATTRIBUTES attribute-list :: variable-list

where in free-form source code only whitespace is allowed before !GCC$ and in fixed-form source code !GCC , c G C C , cGCC ,cGCC or *GCC$ shall start in the first column.

For procedures, the compiler directives shall be placed into the body of the procedure; for variables and procedure pointers, they shall be in the same declaration part as the variable or procedure pointer.

解决方案请看
https://stackoverflow.com/questions/64835950/error-access-violation-reading-0x0000000a-when-call-fortran-dll-made-by-gfortran

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pyengine

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值