C# 在 Fortran dll 中找不到入口点

发布于 10-12 06:39 字数 1157 浏览 7 评论 0原文


我得到了一个可以运行的 FORTRAN 程序,我必须为其编写 C# GUI(不要问为什么)。这个程序已经有FORTRAN GUI,所以我提取了所有的计算子程序并将其放入FORTRAN dll中。该dll由4个文件组成:1个静态库、1个FORTRAN77文件(.for)和2个FORTRAN90文件(.f90)。我已将应从 C# 代码中调用的所有子例程放入 EXPORT.f90 中。
FORTRAN 代码:

MODULE MYVAR
  REAL*8 LK
  COMMON LK
END MODULE    

SUBROUTINE SETLK(NEWLK)
  !DEC$ ATTRIBUTES DLLEXPORT :: SETLK
  USE MYVAR
  REAL*8 NEWLK
  LK = NEWLK
END

SUBROUTINE GETLK(LKOUT)
  !DEC$ ATTRIBUTES DLLEXPORT :: GETLK
  USE MYVAR
  REAL*8, INTENT(OUT):: LKOUT
  LKOUT = LK
END

现在我尝试在 C# 中调用它们,

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl,
EntryPoint="SETLK")]
public static extern void SETLK(ref double NEWLK);

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl,
EntryPoint="GETLK")]
public static extern void GETLK(out double LKOUT);


static void Main(string[] args)
{
    double d1 = 1.234;
    SETLK(ref d1);
    double d2;
    GETLK(out d2);
    Console.WriteLine(d2.ToString());
}

但出现 EntryPointNotFoundException“无法在 'MYDLL.dll' 中找到入口点 'SETLK'”。我需要做什么才能使其正常工作?
谢谢

I was given a working FORTRAN program and i have to write C# GUI for it (don't ask why). This program already has FORTRAN GUI, so i exctracted all the computing subroutines and put it into FORTRAN dll. This dll is built of 4 files: one static library, one FORTRAN77 file(.for) and two FORTRAN90 files(.f90). I've put all subroutines supposed to be called from within C# code into EXPORT.f90.
FORTRAN CODE:

MODULE MYVAR
  REAL*8 LK
  COMMON LK
END MODULE    

SUBROUTINE SETLK(NEWLK)
  !DEC$ ATTRIBUTES DLLEXPORT :: SETLK
  USE MYVAR
  REAL*8 NEWLK
  LK = NEWLK
END

SUBROUTINE GETLK(LKOUT)
  !DEC$ ATTRIBUTES DLLEXPORT :: GETLK
  USE MYVAR
  REAL*8, INTENT(OUT):: LKOUT
  LKOUT = LK
END

Now i'm trying to call them in C#

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl,
EntryPoint="SETLK")]
public static extern void SETLK(ref double NEWLK);

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl,
EntryPoint="GETLK")]
public static extern void GETLK(out double LKOUT);


static void Main(string[] args)
{
    double d1 = 1.234;
    SETLK(ref d1);
    double d2;
    GETLK(out d2);
    Console.WriteLine(d2.ToString());
}

I get EntryPointNotFoundException "Fail to find entry point 'SETLK' in 'MYDLL.dll'". What do i have to do to make it work?
Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔2024-10-19 06:39:18

此线程建议您需要一个 .def 文件来声明函数导出(就像您在本机 Windows 编程中所做的那样)

This thread suggests you need a .def file to declare the function exports (just as you used to in native Windows programming)

荆棘i2024-10-19 06:39:18

使用 PE 资源管理器等工具查看您的 dll。它会告诉您导出了哪些确切的函数。

Look into your dll with a tool like PE explorer. It will tell you what exact functions are exported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文