我試圖學習如何從Fortran可執行文件在Windows中調用fortran dll中的函數。我在eclipse中使用gfortran 4.7和photran。如何使用gfortran的loadlibrary和getprocaddress?
我的測試DLL在hello.f90單一功能:
hello.f90
subroutine hello
implicit none
print *, "Hello World!"
end subroutine hello
與下面的Makefile:
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
的makefile
all:
gfortran -Wall -pedantic -fcray-pointer main.f90
錯誤消息是那個函數LoadLibrary(和getprocaddress)沒有IMPLICIT類型。我懷疑這意味着這些函數沒有定義,我需要以某種方式包含它們的頭文件。是對的嗎?我發現在C調用LoadLibrary聲明:\ MinGW的\包括\ WINBASE.H
歡呼聲,
馬克
我不再使用Windows,所以我不是100%確定,但不應該在「hello.dll」和「hello_」之後有一個'char(0)'使它結束行?? –