繁体   English   中英

C#中的Fortran dll导致无法找到入口点错误

[英]Fortran dll in C# gives Unable to find an entry point error

在这里寻求帮助。 我试图通过Windows 10上的Visual Studio 2017在C#应用程序中使用fortran dll。我从没见过fortran代码。 因此,我使用记事本++中的简单程序创建了一个示例dll。

subroutine Add(x, y, total)BIND(C,NAME="Add")

!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'Add'::Add

integer, intent (in) :: x
integer, intent (in) :: y
integer, intent (inout) :: total   

total = x + y
end subroutine 

我在Windows 10中使用MingW fortran编译器通过以下命令编译了此代码(名为console.f90的一个文件):

gfortran -c -o C:\Users\Desktop\Temp\console.o C:\Users\Desktop\Temp\console.f90
gfortran -shared -mrtd -o C:\Users\Desktop\Temp\console.dll C:\Users\Desktop\Temp\console.o

这给了我console.dll。

现在,我在VS 2017中打开了一个新的C#控制台项目。将体系结构更改为x86(x64给我带来了错误的格式错误)。 将fortran dll(console.dll)放在与我的项目相同的文件夹中,并包含在项目中,并将属性设置为“如果更新则复制”,以便将其复制到bin \\ debug。

将此行写为P / Invoke

[DllImport("console.dll", EntryPoint = "Add", CallingConvention = CallingConvention.StdCall)]
public static extern void Add([In] int x, [In] int y, [In, Out] int t);

然后在我的主要功能中使用了

int a = 12;
int b = 30;
int t = 0;
Add(a, b, t);

虽然在运行应用程序时执行Add(a,b,t)的那一刻,我却收到了一个'EntryPointNotFound'异常。 因此,我使用了DependencyWalker和Dumpbin来查看函数是否已导出且名称正确。 结果如下:

垃圾箱屏幕

依赖行者

我看到我的dll是x86,其他的是x64,这是问题吗? 依赖项查询器还显示了3个dll依赖项“ lib ...”。 我也将它们放置在项目文件夹中,并应用了相同的属性。 仍然没有运气。 感谢您的帮助。 谢谢

我已经将平台选择设置为Debug,这导致了问题。 通过配置管理器添加x86选项并选择相同选项可以解决我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM