具有链接dll的目标文件中的符号大写是否重要? [英] Does symbol capitalization matter in object files with a linked dll?

查看:93
本文介绍了具有链接dll的目标文件中的符号大写是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让gfortran编译器在Windows上的MATLAB中工作,以创建 mex文件.不支持Gfortran,但是支持Intel Fortran编译器,这使我相信Fortran编译器应该能够使用MATLAB库编译Fortran源代码.

I'm trying to get the gfortran compiler working in MATLAB on Windows to create mex files. Gfortran isn't supported, but the Intel Fortran compiler is, which leads me to believe that a Fortran compiler should be able to compile Fortran source using MATLAB libraries.

我先前的问题中所述,对于应该来自MATLAB库的每个符号,我都会收到未定义的引用"错误.我认为这是错误的,因为未按

As detailed in my previous question, I get an "undefined reference" error for every symbol that should come from the MATLAB libraries. I thought this was an error with the preprocessor not getting invoked as suggested in a question on MathWorks Answers, but after looking into this problem some more I don't believe that's the problem since the errors refer to things like "mxisnumeric800" which is a substitution made in the fintrf.h header.

我使用dumpbin检查了从所需库libmx.dll和libmex.dll导出的符号.导出的符号包括两个与mxisnumeric800接近的符号:

I checked the symbols exported from the required libraries, libmx.dll and libmex.dll, using dumpbin. The exported symbols include two that are close to mxisnumeric800:

  Section contains the following exports for libmx.dll
...
       1431  596 0009F200 MXISNUMERIC800
...
       1747  6D2 000ABC24 mxIsNumeric_800
...

我可以理解,由于多余的下划线,为什么不能将mxIsNumeric_800理解为同一符号,但是大写字母也有区别吗?

I can understand why mxIsNumeric_800 wouldn't be read as the same symbol due to the extra underscore, but does capitalization make a difference too?

推荐答案

您遇到的问题是,Fortran是敏感的语言中的一种情况.因此,如果您有子例程foo:

The problem you are having is that Fortran is a case insensitive language. So if you have a subroutine foo:

subroutine foo(x)
  real :: x
end subroutine foo

您可以使用以下任意一种来调用它:

you could call it with any of the following:

call foo(x)
call FOO(x)
call fOo(x)

使用此功能构建目标文件或库时,符号名称将取决于编译器.如果在Linux系统上使用Gfortran,它将始终将符号名称小写并在其后添加下划线,例如

When you build an object file or library with this function, the symbol name will be compiler dependent. In case of Gfortran on a Linux system, it will always downcase the symbol name and add an underscore behind it such as

foo_

在Windows系统上,其行为将有所不同(请参见此处此处)) ,甚至不同的编译器也会有不同的想法.

On Windows Systems it will behave differently (see here and here), and even different compilers will have different ideas.

那么,这到底意味着什么?

这意味着当您编写如下子程序调用时:

This means that when you write a subroutine call like:

 call mxIsNumeric_800(arg1, arg2, arg3)

Gfortran会尝试将其链接到符号mxisnumeric_800_,而不是您期望的符号.在过去,这通常会导致难看的骇客入侵,而且非常难以携带. Fortran 2003通过引入BIND属性以明确的方式解决了此问题.一个允许程序员通知编译器该对象应作为非Fortran对象处理的属性(请参阅

Gfortran will attempt to link it against a symbol mxisnumeric_800_ and not the symbol you expect. In the past, this often resulted into ugly hacks which were very not-portable. Fortran 2003, addressed this issue in a clear way by introducing the BIND attribute. An attribute which allows the programmer to inform the compiler that this object should be handled as a non-Fortran object (cfr. Section 15.5 of the F2008 standard).

使用此属性,您现在可以定义一个Fortran可以完全理解的接口,并且编译器知道在哪里可以找到具有相应大小写敏感性的相应符号.例如

With this attribute, you can now define an interface that is fully understood by Fortran and that the compiler knows where to find the corresponding symbol with its respective case-sensitivity. Eg.

interface
   subroutine mxisnumeric(arg1,arg2,arg3) BIND(C, NAME="mxIsNumeric_800")
      use, intrinsic :: iso_c_binding
      implicit none
      real(c_float) :: arg1
      integer(c_int) :: arg2
      character(c_char) :: arg3
   end subroutine mxisnumeric
end interface

可以在此处找到更多详细信息.

Some more details can be found here.

这篇关于具有链接dll的目标文件中的符号大写是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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