Discussion:
Lahey Fortran with Winapi functions
(too old to reply)
m***@technip.com
2015-05-28 12:50:45 UTC
Permalink
A legacy fortran program is being upgraded from compiling with Lahey v5.6 to Lahey v7.6 to be able to compile and link Lahey with a Windows 7 64 bit OS. The current version runs on Windows XP.

Winapi calls are made using the DLL_IMPORT statement. A sample Function block is shown below:

INTEGER FUNCTION ACTIVWIN()
! Return the handle of the active window attached to the caller's msg queue.
! Uses Win API function GetActiveWindow.
! Compile with switch: -ml bc or with switch: -ml winapi

DLL_IMPORT GetActiveWindow
INTEGER :: GetActiveWindow

ACTIVWIN= GetActiveWindow()
RETURN
END

All the separate files in the program compile with no errors reported.

Compile command used: lf95 @F90RTNS.LST -c -winconsole -winapi -ml bc -mod "C:\Program Files (x86)\Lahey-Fujitsu Fortran\v7.6\WiSK\lib.l9m"

When trying to link the object files the error below occurs for all Winapi functions called.

Lahey/Fujitsu Fortran 95 Compiler Release 7.60.01 S/N: xxxxxxxxx
Copyright (C) 1994-2014 Lahey Computer Systems. All rights reserved.
Copyright (C) 1998-2014 FUJITSU LIMITED. All rights reserved.

ACTIVWIN.obj : error LNK2001: unresolved external symbol GetActiveWindow

The linking switches are:

-winconsole -nologo -nc -nco -wisk -ml winapi -map xxxxxx -out xxxxxx -libpath "C:\Program Files (x86)\Lahey-Fujitsu Fortran\v7.6\LF95\Lib"

Is there something that must be changed with the new compiler to enable the Winapi commands to work either in the Fortran code or the compiler switches?
Robert van Amerongen
2015-05-28 17:05:10 UTC
Permalink
Post by m***@technip.com
A legacy fortran program is being upgraded from compiling with Lahey v5.6 to Lahey v7.6 to be able to compile and link Lahey with a Windows 7 64 bit OS. The current version runs on Windows XP.
INTEGER FUNCTION ACTIVWIN()
! Return the handle of the active window attached to the caller's msg queue.
! Uses Win API function GetActiveWindow.
! Compile with switch: -ml bc or with switch: -ml winapi
DLL_IMPORT GetActiveWindow
INTEGER :: GetActiveWindow
ACTIVWIN= GetActiveWindow()
RETURN
END
All the separate files in the program compile with no errors reported.
When trying to link the object files the error below occurs for all Winapi functions called.
Lahey/Fujitsu Fortran 95 Compiler Release 7.60.01 S/N: xxxxxxxxx
Copyright (C) 1994-2014 Lahey Computer Systems. All rights reserved.
Copyright (C) 1998-2014 FUJITSU LIMITED. All rights reserved.
ACTIVWIN.obj : error LNK2001: unresolved external symbol GetActiveWindow
-winconsole -nologo -nc -nco -wisk -ml winapi -map xxxxxx -out xxxxxx -libpath "C:\Program Files (x86)\Lahey-Fujitsu Fortran\v7.6\LF95\Lib"
Is there something that must be changed with the new compiler to enable the Winapi commands to work either in the Fortran code or the compiler switches?
I have no experience with the current Lahey compiler. So dopes the use of a dll with windpw programming. But an unresolved external reference indicates that the application is missing the user32.lib. Further, if you are running with 64 bits, be sure to have ActiveWin and the function to be declared as a 64 bit integer. Preferably INTEGER(KIND=C_INTPTR_T) (Works on both 32 and 64 bits)
Robert
James Van Buskirk
2015-05-28 17:13:50 UTC
Permalink
Post by m***@technip.com
A legacy fortran program is being upgraded from compiling with
Lahey v5.6 to Lahey v7.6 to be able to compile and link Lahey
with a Windows 7 64 bit OS. The current version runs on Windows XP.
Winapi calls are made using the DLL_IMPORT statement. A sample
INTEGER FUNCTION ACTIVWIN()
! Return the handle of the active window attached to the caller's msg queue.
! Uses Win API function GetActiveWindow.
! Compile with switch: -ml bc or with switch: -ml winapi
DLL_IMPORT GetActiveWindow
INTEGER :: GetActiveWindow
ACTIVWIN= GetActiveWindow()
RETURN
END
All the separate files in the program compile with no errors reported.
bc -mod "C:\Program Files (x86)\Lahey-Fujitsu Fortran\v7.6\WiSK\lib.l9m"
When trying to link the object files the error below occurs for all
Winapi functions called.
Lahey/Fujitsu Fortran 95 Compiler Release 7.60.01 S/N: xxxxxxxxx
Copyright (C) 1994-2014 Lahey Computer Systems. All rights reserved.
Copyright (C) 1998-2014 FUJITSU LIMITED. All rights reserved.
ACTIVWIN.obj : error LNK2001: unresolved external symbol GetActiveWindow
-winconsole -nologo -nc -nco -wisk -ml winapi -map xxxxxx -out xxxxxx
-libpath "C:\Program Files (x86)\Lahey-Fujitsu Fortran\v7.6\LF95\Lib"
Is there something that must be changed with the new compiler to enable
the Winapi commands to work either in the Fortran code or the compiler
switches?
My recollection about LF95 is that it ranked between pitiful and useless
for interacting with the Win32 API. The good news is that v. 7.6 includes
gfortran, which can do Win32 API no problem via C interoperability and
the extension !GCC$ ATTRIBUTES STDCALL :: GetActiveWindow . You need to
use the gfortran compiler in there anyway if you want native 64-bit code
(and you DO want native 64-bit code, whether you think you want it or not.)

So even though the original 32-bit Fujitsu compiler had superior f95
conformance features, really at this point the f2003 capabilities of
gfortran are just too compelling at this point in time. I've got some
examples of Win32 API coding with gfortran, such as

http://home.comcast.net/~kmbtib/Fortran_stuff/gridview.zip

which is an adaptation of the OpenGL example from Norman Lawrence's
book to gfortran.

Loading...