C# 在 Fortran dll 中找不到入口点
我得到了一个可以运行的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此线程建议您需要一个 .def 文件来声明函数导出(就像您在本机 Windows 编程中所做的那样)
This thread suggests you need a .def file to declare the function exports (just as you used to in native Windows programming)
使用 PE 资源管理器等工具查看您的 dll。它会告诉您导出了哪些确切的函数。
Look into your dll with a tool like PE explorer. It will tell you what exact functions are exported.