【发布时间】:2013-01-04 22:09:49
【问题描述】:
我正在尝试学习如何从 Windows 上的 fortran 可执行文件调用 fortran dll 中的函数。我在 eclipse 中使用 gfortran 4.7 和 photran。
我的测试 dll 在 hello.f90 中有一个函数:
hello.f90
subroutine hello
implicit none
print *, "Hello World!"
end subroutine hello
使用以下生成文件:
all:
gfortran -Wall -c hello.f90
gfortran -shared -o hello.dll hello.o
Dependency Walker 确认函数“hello_”已导出。
现在我正在尝试构建一个动态调用它的程序。我根据在网上找到的示例构建了以下内容,但无法编译:
main.f90
program main
implicit none
integer :: p
pointer (q, hello)
p = loadlibrary("hello.dll")
q = getprocaddress(p, "hello_")
call hello
end program main
制作文件
all:
gfortran -Wall -pedantic -fcray-pointer main.f90
错误消息是函数 LoadLibrary(和 getprocaddress)没有隐式类型。我怀疑这意味着这些函数没有定义,我需要以某种方式包含它们的标题。是对的吗?我在 c:\mingw\include\winbase.h 中找到了 loadlibrary 的声明
干杯,
马克
【问题讨论】:
-
我不再使用 Windows,所以我不是 100% 确定,但不应该在 "hello.dll" 和 "hello_" 之后有一个
char(0)让它结束这一行吗? ?