C#中的Fortran dll使Unable无法找到入口点错误

问题描述 投票:0回答:1

请求一些帮助。我试图通过Windows 10上的Visual Studio 2017在我的C#应用​​程序中使用fortran dll。我一生中从未见过fortran代码。所以我在notepad ++中创建了一个带有这样简单程序的示例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 

我使用MingW fortran编译器使用以下命令在Windows 10中编译了此代码(1个名为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)放在与我的项目相同的文件夹中并包含在项目中,并将属性设置为“Copy if newer”,以便将其复制到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);

然后在我的Main函数中使用了这个

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

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

Dumpbin screen

Dependency Walker

我看到我的dll是x86而其他的是x64是问题吗?依赖性walker还显示了3 dll依赖'lib ...'。我也将它们放在项目文件夹中并应用了相同的属性。仍然没有运气。这里有任何帮助。谢谢

c# visual-studio-2017 fortran dllimport
1个回答
0
投票

我已经将Platform选择设置为Debug,这导致了问题。通过Configuration Manager添加x86选项并选择相同的修复我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.