|
|
Up |
|
|
  |
Author: James Van BuskirkJames Van Buskirk Date: Nov 9, 2007 20:35
There seems to be a problem with Win32 API and 32-bit gfortran.
C:\gfortran\test>type hello.f90
! hello.f90
module mykinds
implicit none
integer, parameter :: ik4 = selected_int_kind(9)
integer, parameter :: ik8 = selected_int_kind(18)
end module mykinds
module Win32
use mykinds
implicit none
private
|
| Show full article (3.46Kb) |
|
| | 39 Comments |
|
  |
Author: Steve LionelSteve Lionel Date: Nov 10, 2007 05:24
On Nov 9, 11:35 pm, "James Van Buskirk" comcast.net> wrote:
> The issue is that the name of a Win32 API function can't be converted
> into the name ld.exe likes,
The problem is bigger than that. All Win32 API routines on 32-bit
Windows use the STDCALL calling mechanism, which has a naming
convention adding the @n at the end of the name to signify the number
of bytes to pop off the stack on return. gfortran, like most Fortran
compilers on Windows (except for CVF and MSFPS) default to the C
convention. If you call a STDCALL routine but the compiler thinks it
is a C routine, the stack gets popped twice and you corrupt the
stack. Things go downhill from there.
You will have to see what gfortran offers for specifying that an
external routine is STDCALL. Whatever it is, it's going to be an
extension and probably not part of BIND. In Intel Fortran, for
example, one uses !DEC$ ATTRIBUTES STDCALL :: routinename
Never, ever attempt to paper over the naming convention difference by
simply adding the @n suffix - the errors this will cause can be
mystifying.
Steve
|
| |
|
| | no comments |
|
  |
Author: alexzenkalexzenk Date: Nov 10, 2007 09:18
On Nov 10, 7:35 am, "James Van Buskirk" comcast.net> wrote:
> There seems to be a problem with Win32 API and 32-bit gfortran.
>
Call Win32 API from gfortran is possible, but for this you should
write for each used Win32 API functions interface subroutine on C.
In consequence of significant difficulties of the mixed programming
for Windows, such approach impractical. Writing of the whole program
on C will probably more simply.
Here is example such working program
---------------File myfirst1.f95------------------------------------
SUBROUTINE FortranSub()
integer i, j
CHARACTER(LEN = 15):: Text
CHARACTER(LEN = 15) :: Caption
i = 0
j = 0
Text = "Hello All"//CHAR...
|
| Show full article (1.84Kb) |
| no comments |
|
  |
Author: Gary ScottGary Scott Date: Nov 10, 2007 09:23
alexzenk wrote:
> On Nov 10, 7:35 am, "James Van Buskirk" comcast.net> wrote:
>
>>There seems to be a problem with Win32 API and 32-bit gfortran.
>>
>
>
> Call Win32 API from gfortran is possible, but for this you should
> write for each used Win32 API functions interface subroutine on C.
> In consequence of significant difficulties of the mixed programming
> for Windows, such approach impractical. Writing of the whole program
> on C will probably more simply.
Not an acceptable solution. A compiler targeted at a specific OS MUST
be able to directly call OS APIs. I will never ever use a compiler
which does not support this.
> Here is example such working program
>
>
> ---------------File myfirst1.f95------------------------------------
> SUBROUTINE FortranSub()
> integer i, j
> CHARACTER(LEN = 15):: Text
> CHARACTER(LEN...
|
| Show full article (2.50Kb) |
| no comments |
|
  |
Author: e p chandlere p chandler Date: Nov 10, 2007 09:39
On Nov 9, 11:35 pm, "James Van Buskirk" comcast.net> wrote:
> There seems to be a problem with Win32 API and 32-bit gfortran.
>
> C:\gfortran\test>type hello.f90
> ! hello.f90
>
> module mykinds
> implicit none
> integer, parameter :: ik4 = selected_int_kind(9)
> integer, parameter :: ik8 = selected_int_kind(18)
> end module mykinds
>
> module Win32
> use mykinds
> implicit none
> private
>
> public GetStdHandle
> interface
> function GetStdHandle(nStdHandle) bind(C,name='GetStdHandle') ...
|
| Show full article (4.58Kb) |
| no comments |
|
  |
Author: James Van BuskirkJames Van Buskirk Date: Nov 10, 2007 13:00
> Never, ever attempt to paper over the naming convention difference by
> simply adding the @n suffix - the errors this will cause can be
> mystifying.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
|
| |
| no comments |
|
  |
Author: James Van BuskirkJames Van Buskirk Date: Nov 10, 2007 14:48
> One of your problems is that WriteConsoleA seems not to be there at
> all.
> Replacing WriteConsoleA with WriteFile in your source code and
> compiling with g95 gives
Well, I find the string 'WriteConsoleA' 5 times each in:
C:\g95\lib\libkernel32.a
C:\gfortran\lib\libkernel32.a
C:\gfortran\win64\x86_64-pc-mingw32\lib\libkernel32.a
so I don't think that's the problem. Doing the g95 thing with @n:
C:\g95\test>type hello.f90
! hello.f90
module mykinds
implicit none
integer, parameter :: ik4 = selected_int_kind(9)
integer, parameter :: ik8 = selected_int_kind(18)
end module mykinds
|
| Show full article (2.97Kb) |
| no comments |
|
  |
Author: Steve LionelSteve Lionel Date: Nov 10, 2007 18:20
On Nov 10, 4:00 pm, "James Van Buskirk" comcast.net> wrote:
>> Never, ever attempt to paper over the naming convention difference by
>> simply adding the @n suffix - the errors this will cause can be
>> mystifying.
|
| Show full article (4.13Kb) |
| no comments |
|
  |
Author: e p chandlere p chandler Date: Nov 10, 2007 18:53
On Nov 10, 5:48 pm, "James Van Buskirk" comcast.net> wrote:
>> One of your problems is that WriteConsoleA seems not to be there at
>> all.
>> Replacing WriteConsoleA with WriteFile in your source code and
>> compiling with g95 gives
>
> Well, I find the string 'WriteConsoleA' 5 times each in:
>
> C:\g95\lib\libkernel32.a
> C:\gfortran\lib\libkernel32.a
> C:\gfortran\win64\x86_64-pc-mingw32\lib\libkernel32.a
>
> so I don't think that's the problem. Doing the g95 thing with @n:
>
> C:\g95\test>type hello.f90
> ! hello.f90
>
> module mykinds ...
|
| Show full article (4.51Kb) |
| no comments |
|
  |
|
|
  |
Author: James Van BuskirkJames Van Buskirk Date: Nov 11, 2007 01:22
> You want to call some Win32 API routines from Fortran. These are
> STDCALL routines and their global symbols have the @n suffix.
> Compilers which support STDCALL will automatically add the proper @n...
|
| Show full article (2.65Kb) |
| no comments |
|
|
|
|