gfortran, DLL, underscore

前端 未结 4 1481
我在风中等你
我在风中等你 2021-01-25 14:35

I want to access some subroutines from a third party DLL. The functions use STDCALL as the calling convention.

Running dumpbin /export foo.dll gives me some

4条回答
  •  时光取名叫无心
    2021-01-25 15:07

    Just wanted to expand on M.S.B's -fno-underscoring answer: You may run into issues if using f2c & g77. From the gfortran documentation:

    With -funderscoring in effect, GNU Fortran appends one underscore to external names with no underscores. This is done to ensure compatibility with code produced by many UNIX Fortran compilers.

    Caution: The default behavior of GNU Fortran is incompatible with f2c and g77, please use the -ff2c option if you want object files compiled with GNU Fortran to be compatible with object code created with these tools.

    Use of -fno-underscoring is not recommended unless you are experimenting with issues such as integration of GNU Fortran into existing system environments (vis-à-vis existing libraries, tools, and so on).

    You might need to recompile the DLL with something like -fno-underscoring to remove the underscores from the DLL.

    I've run into portability issues related to underscore prefix/suffix by certain Fortran compilers: Some compilers _prefix or suffix_ by default, while others don't! My solution has been preprocessor directives:

    #ifdef LC_UNSC
    #define  GET_DIP_MOMENT get_dip_moment_
    #elif LC_NOUNSC
    #define  GET_DIP_MOMENT get_dip_moment
    #endif
    ...
         call GET_DIP_MOMENT()
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题