我正在尝试编译一个子例程 sendmsg.f90,我们以前用 lf90 作为 32 位现在用 gcc 作为 64 位编译。目的是将它与其他用 gcc 编译的 64 位子程序链接起来。
subroutine UpdateDisplay(WINHAND,NTPS,QCANCEL,NITER)
use win32mod
implicit none
integer WINHAND, NTPS, MESSNUM, NITER, QCANCEL
! SendMessageA is a Windows function
! WINHAND = handle of window (from ISDev code)
! MESSNUM = message number (assigned by ISDev)
! NTPS = number of year iteration currently on (WParam)
! DUM = 0 (LParam)
MESSNUM = 1114
QCANCEL = SendMessageA(carg(WINHAND),carg(MESSNUM),carg(NTPS), carg(NITER))
end subroutine
我们有 Lahey Fortran 7.5,它有 lf90 编译器和 gcc(它使用 gfortran)和一个叫做 lgf 的东西(我想它使用 gcc,对吗?)。
我是 Windows 编程(和 Fortran)的新手。使用 gcc 编译的代码可以调用 Windows API 吗?我应该使用 ISO_C_BINDING 吗?
我应该这样做还是应该尝试将 lf90 创建的 .obj 文件与 gcc 创建的 .o 文件链接?
谢谢你的帮助!
更新:我尝试使用以下方法调用 Windows API:
MODULE SND_C
interface
integer(C_LONG) FUNCTION SendMessage &
(WINHAND,MESSNUM,NTPS, NITER) &
bind(C,Name='SendMessage')
use ISO_C_BINDING
implicit NONE
integer(C_LONG), VALUE :: WINHAND
integer(C_LONG), VALUE :: MESSNUM
integer(C_LONG), VALUE :: NTPS
integer(C_LONG), VALUE :: NITER
end function SendMessage
end interface
END MODULE SND_C
subroutine UpdateDisplay(WINHAND,NTPS,QCANCEL,NITER)
USE ISO_C_BINDING, ONLY: C_LONG
USE SND_C
implicit none
integer(C_LONG) WINHAND, NTPS, MESSNUM, NITER, QCANCEL
! SendMessageA is a Windows function
! WINHAND = handle of window (from ISDev code)
! MESSNUM = message number (assigned by ISDev)
! NTPS = number of year iteration currently on (WParam)
! DUM = 0 (LParam)
!GCC$ ATTRIBUTES DLLEXPORT :: UpdateDisplay
MESSNUM = 1114
QCANCEL = SendMessage(WINHAND,MESSNUM,NTPS, NITER)
end subroutine
但是当我尝试用“gcc -m64 sendmsg.f90”编译时,我得到了错误:
C:\Users\StephanieJ\Documents\Lahey-Fujitsu Fortran>gcc -m64 sendmsg.f90
c:/progra~2/lahey-~1/v7.5/gcc-gf~1/bin/../lib/gcc/x86_64-w64-mingw32/4.7.4/../..
/../../x86_64-w64-mingw32/lib/../lib/crt2.o: In function `__tmainCRTStartup':
c:\gccbuild\mingw-crt\build32-64\mingw-w64-crt/../../mingwsvn/mingw-w64-crt/crt/
crtexe.c:323: undefined reference to `__laheypause'
C:\Users\STEPHA~2\AppData\Local\Temp\ccWjjo5b.o:sendmsg.f90:(.text+0x3e): undefi
ned reference to `SendMessage'
c:/progra~2/lahey-~1/v7.5/gcc-gf~1/bin/../lib/gcc/x86_64-w64-mingw32/4.7.4/../..
/../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):
In function `main':
c:\gccbuild\mingw-crt\build32-64\mingw-w64-crt/../../mingwsvn/mingw-w64-crt/crt/
crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
这种方法有意义吗?为什么我对 SendMessage 的引用未定义?