Re: gfortran iso c bindings - capabilities
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Sun, 16 Mar 2008 16:07:01 -0600
"*** Hendrickson" <***.hendrickson@xxxxxxx> wrote in message
news:sa%Cj.13674$D_3.7386@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I haven't been following this thread in detail. But, the processor is
free to pick any companion processor it chooses. In particular, I
think it can make a command line driven decision to pick the companion
that uses whatever calling conventions the user wants. I think that was
the intent of the interoperability feature. A Fortran processor is
likely to have several available companions and the user picks one at
compile time. The various companions could be the same C compiler
invoked with different command line options.
That is just what I am trying to do -- use command-line switches to
determine whether the calling convention is _cdecl or _stdcall.
Bind(C) won't work well if more than one calling sequence is needed
for the same Fortran program.
That may be, but I am hoping to at least be able to limp along.
The current example is:
http://home.comcast.net/~kmbtib/Fortran_stuff/multi_test.ZIP
Here's how it works on xp-x64:
C:\gfortran\test\multi_test>gfortran -v
Built by Equation Solution (http://www.Equation.com).
Using built-in specs.
Target: x86_64-pc-mingw32
Configured with:
.../gcc-4.4-20080307-mingw/configure --host=x86_64-pc-mingw32 --
build=x86_64-unknown-linux-gnu --target=x86_64-pc-mingw32 --prefix=/home/gfortra
n/gcc-home/binary/mingw32/native/x86_64/gcc/4.4-20080307 --with-gmp=/home/gfortr
an/gcc-home/binary/mingw32/native/x86_64/gmp --with-mpfr=/home/gfortran/gcc-home
/binary/mingw32/native/x86_64/mpfr --with-sysroot=/home/gfortran/gcc-home/binary
/mingw32/cross/x86_64/gcc/4.4-20080307 --with-gcc --with-gnu-ld --with-gnu-as
--
disable-shared --disable-nls --disable-tls --enable-languages=c,fortran --enable
-libgomp --enable-threads=win32 --disable-win32-registry
Thread model: win32
gcc version 4.4.0 20080307 (experimental) (GCC)
C:\gfortran\test\multi_test>type make_multi_test.bat
@echo off
set gfc=C:\gfortran\win64\bin\x86_64-pc-mingw32-gfortran
rem set gfc=C:\gfortran\bin\gfortran
%gfc% -c user32_cdecl.f90
if %errorlevel% NEQ 0 goto errorexit
%gfc% -mrtd -enable-stdcall-fixup -c user32_stdcall.f90
if %errorlevel% NEQ 0 goto errorexit
%gfc% -c user32.f90
if %errorlevel% NEQ 0 goto errorexit
%gfc% -mrtd -enable-stdcall-fixup -c kernel32.f90
if %errorlevel% NEQ 0 goto errorexit
%gfc% multi_test.f90 -lkernel32 -luser32 -omulti_test
if %errorlevel% NEQ 0 goto errorexit
goto goodexit
:errorexit
echo Sorry, error detected
:goodexit
C:\gfortran\test\multi_test>make_multi_test
f951.exe: warning: -mrtd is ignored in 64bit mode
f951.exe: warning: -mrtd is ignored in 64bit mode
C:\gfortran\test\multi_test>multi_test
Address of GetStdHandle = 0000000000401740
As you can see, this version of make_multi_test.bat uses the version
of gfortran that makes 64-bit executables. The one in the *.ZIP
archive is geared towards 32-bit output. The program will need
Win32 APIs, some of which are STDCALL, but one of which is not.
The files containing the interface blocks, user32_cdecl.f90 and
kernel32.f90, are compiled with different command-line switches.
The compiler is supposed to incorporate the information about the
calling convention in the data strutures describing the explicit
interfaces in user32_cdecl.mod and kernel32.mod, which should
eventually get passed along to the compiler when it compiles
multi_test.f90 so that all procedures will be invoked correctly.
This works fine in the x64 world because there is only one calling
convention there and there is no need to create another one because
that ISA isn't as short on registers as in *32-land. This isn't
really getting tested on 32-bit windows:
C:\gfortran\test\multi_test>gfortran -v
Using built-in specs.
Target: i586-pc-mingw32
Configured with:
.../trunk/configure --prefix=/mingw --enable-languages=c,fortran
--with-gmp=/home/FX/local --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --dis
able-werror --enable-bootstrap --enable-threads --disable-nls --build=i586-pc-mi
ngw32 --enable-libgomp --disable-shared
Thread model: win32
gcc version 4.4.0 20080312 (experimental) [trunk revision 133139] (GCC)
C:\gfortran\test\multi_test>make_multi_test
C:\DOCUME~1\James\LOCALS~1\Temp/ccfZDSSl.o:multi_test.f90:(.text+0x2b):
undefine
d reference to `GetStdHandle'
C:\DOCUME~1\James\LOCALS~1\Temp/ccfZDSSl.o:multi_test.f90:(.text+0xab):
undefine
d reference to `GetStdHandle'
C:\DOCUME~1\James\LOCALS~1\Temp/ccfZDSSl.o:multi_test.f90:(.text+0x15a):
undefin
ed reference to `WriteFile'
collect2: ld returned 1 exit status
Sorry, error detected
The -enable-stdcall-fixup switch doesn't work except for a very few
functions, so gfortran isn't making the right names to link with
libkernel32.a and libuser32.a. Now, if this switch magically worked,
it would be possible to determine whether my approach is going to
work in gfortran, but for now it's a big question mark.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
.
- Follow-Ups:
- Re: gfortran iso c bindings - capabilities
- From: FX
- Re: gfortran iso c bindings - capabilities
- From: James Van Buskirk
- Re: gfortran iso c bindings - capabilities
- References:
- gfortran iso c bindings - capabilities
- From: Brendan
- Re: gfortran iso c bindings - capabilities
- From: James Van Buskirk
- Re: gfortran iso c bindings - capabilities
- From: FX
- Re: gfortran iso c bindings - capabilities
- From: James Van Buskirk
- Re: gfortran iso c bindings - capabilities
- From: *** Hendrickson
- gfortran iso c bindings - capabilities
- Prev by Date: Re: BIND(C) EXPORT / IMPORT of Fortran variables
- Next by Date: Re: New to FORTRAN - Reformatting One Column to Multiple Columns
- Previous by thread: Re: gfortran iso c bindings - capabilities
- Next by thread: Re: gfortran iso c bindings - capabilities
- Index(es):