From: Elijah Cardon on 25 Sep 2006 23:31 I took my first swing at fortran since when Reagan was president, and think that I did ok with the IDE from silverfrost f95. With the IDE, I'm trying to make a dll that gets picked up by VB. Elsethread (subject: general query), e.p. chandler suggested the following make file for this dll in a fortran that looks to be the analog of gcc: make.bat: g95 -s -shared -mrtd -o test.dll test.def test.f95 g95 is the MinGW version. The options are: -s = strip debug info -shared = make a dll -mrtd = calling convention is stdcall -o = output file http://www.billfordx.net/screendumps/dump1.htm Anyways, the trick I think is going to be what a person does about the name mangling, and figuring out where files belong in the IDE. I can't really show output, because the night's only half over, and I'm going to fire up the VB end. Any comment appreciated. EC
From: e p chandler on 26 Sep 2006 10:39 Elijah Cardon wrote: > I took my first swing at fortran since when Reagan was president, and think > that I did ok with the IDE from silverfrost f95. With the IDE, I'm trying > to make a dll that gets picked up by VB. Elsethread (subject: general > query), e.p. chandler suggested the following make file for this dll in a > fortran that looks to be the analog of gcc: > > make.bat: > > g95 -s -shared -mrtd -o test.dll test.def test.f95 > > g95 is the MinGW version. The options are: > > -s = strip debug info > -shared = make a dll > -mrtd = calling convention is stdcall > -o = output file > > > http://www.billfordx.net/screendumps/dump1.htm > > Anyways, the trick I think is going to be what a person does about the name > mangling, and figuring out where files belong in the IDE. I can't really > show output, because the night's only half over, and I'm going to fire up > the VB end. Any comment appreciated. EC As posted you have messed up the Fortran source code a bit. Check your variable names. I do not believe that Salford Fortran uses .def files as g95 (or g77) does. [I have just gone back and re-created a set of files to generate a test dll using Salford Fortran 77 (FTN77 PE). FTN77 will create a dll, but it uses the wrong calling convention (C). VB requires stdcall. Salford once documented and offered a program that wrapped its object code into a dll but that process is no longer documented and the program is no longer available. However, it is possible to create a wrapper in C and include it in Salford's dll making process. MinGW versions of gcc do work here. {FX Coudert supplies one with his gfortran binaries. Thanks! :-)} I know Salford Fortran 95 (PE) also works when built from the command line but I have yet to re-construct my files to do so. Later today, I hope. :-).] -- e-mail: epc8 at juno dot com -- Elliot
From: Craig Powers on 26 Sep 2006 13:37 e p chandler wrote: > Elijah Cardon wrote: >> I took my first swing at fortran since when Reagan was president, and think >> that I did ok with the IDE from silverfrost f95. With the IDE, I'm trying >> to make a dll that gets picked up by VB. Elsethread (subject: general >> query), e.p. chandler suggested the following make file for this dll in a >> fortran that looks to be the analog of gcc: >> >> make.bat: >> >> g95 -s -shared -mrtd -o test.dll test.def test.f95 >> >> g95 is the MinGW version. The options are: >> >> -s = strip debug info >> -shared = make a dll >> -mrtd = calling convention is stdcall >> -o = output file >> >> >> http://www.billfordx.net/screendumps/dump1.htm >> >> Anyways, the trick I think is going to be what a person does about the name >> mangling, and figuring out where files belong in the IDE. I can't really >> show output, because the night's only half over, and I'm going to fire up >> the VB end. Any comment appreciated. EC > > As posted you have messed up the Fortran source code a bit. Check your > variable names. I do not believe that Salford Fortran uses .def files > as g95 (or g77) does. ..def files are fundamental to the Windows linker, rather than to a particular compiler. As long as Salford/Silverfrost does some sort of name mangling on exported routines, and passes a .def file through to the linker, then it is appropriate to use the .def file to rename the exports according to your preference. (The calling convention bit that I snipped is a more serious problem... DVF and CVF (and presumably IVF) allow one to use compiler directives to influence the choice of calling convention.)
From: e p chandler on 26 Sep 2006 18:09 Craig Powers wrote: > e p chandler wrote: > > Elijah Cardon wrote: > >> I took my first swing at fortran since when Reagan was president, and think > >> that I did ok with the IDE from silverfrost f95. With the IDE, I'm trying > >> to make a dll that gets picked up by VB. Elsethread (subject: general > >> query), e.p. chandler suggested the following make file for this dll in a > >> fortran that looks to be the analog of gcc: > >> > >> make.bat: > >> > >> g95 -s -shared -mrtd -o test.dll test.def test.f95 > >> > >> g95 is the MinGW version. The options are: > >> > >> -s = strip debug info > >> -shared = make a dll > >> -mrtd = calling convention is stdcall > >> -o = output file > >> > >> > >> http://www.billfordx.net/screendumps/dump1.htm > >> > >> Anyways, the trick I think is going to be what a person does about the name > >> mangling, and figuring out where files belong in the IDE. I can't really > >> show output, because the night's only half over, and I'm going to fire up > >> the VB end. Any comment appreciated. EC > > > > As posted you have messed up the Fortran source code a bit. Check your > > variable names. I do not believe that Salford Fortran uses .def files > > as g95 (or g77) does. > > .def files are fundamental to the Windows linker, rather than to a > particular compiler. As long as Salford/Silverfrost does some sort of > name mangling on exported routines, and passes a .def file through to > the linker, then it is appropriate to use the .def file to rename the > exports according to your preference. Salford provides its own linker (SLINK) which AFAIK does not use .def files. In addition it has command line options to un-mangle exported symbols or map exported symbols to aliases. Salford's docs for Fortran 77 describe how the linker works in detail and how it searches various system dlls and import libraries. So I've never used MS-LINK or gcc's ld for this purpose. Once I work through the process for Salford Fortran 95 (FTN95) I will post it here. > > > (The calling convention bit that I snipped is a more serious problem... > DVF and CVF (and presumably IVF) allow one to use compiler directives to > influence the choice of calling convention.) That's a key problem on Windows. I suspect that even the F2003 C-interop does not help here. Each compiler has its own (non-standard) way to handle sepcifying a dll, exporting symbols, name mangling, calling convention, argument passing, etc., etc. Add in the complexities of passing arguments other than simple integers or reals plus the possibilities of different object file formats (OMF vs COFF) and it's a real can of worms. :-). g95 and gfortran, Salford, Open Watcom, Lahey, DVF/CVF/IVF all are different here. One of the problems for me was finding out how to get g77 and later gfortran and g95 to use stdcall in exported routines. [Thanks to Mummit Khan for pointing out the -mrtd switch. It sure was better than writing wrappers in C as in my first attempts.] -- Elliot -- e-mail: epc8 at juno dot com
From: e p chandler on 26 Sep 2006 22:50
Elijah Cardon wrote: > I took my first swing at fortran since when Reagan was president, and think > that I did ok with the IDE from silverfrost f95. With the IDE, I'm trying > to make a dll that gets picked up by VB. Elsethread (subject: general > query), e.p. chandler suggested the following make file for this dll in a > fortran that looks to be the analog of gcc: > > make.bat: > > g95 -s -shared -mrtd -o test.dll test.def test.f95 > > g95 is the MinGW version. The options are: > > -s = strip debug info > -shared = make a dll > -mrtd = calling convention is stdcall > -o = output file > > > http://www.billfordx.net/screendumps/dump1.htm > > Anyways, the trick I think is going to be what a person does about the name > mangling, and figuring out where files belong in the IDE. I can't really > show output, because the night's only half over, and I'm going to fire up > the VB end. Any comment appreciated. EC Here is the command line version for FTN95: test.f95: f_stdcall function isub2(i,j) isub2=i-j end make.bat: ftn95 -c test slink -dll -export:isub2=_ISUB2@8 test.obj notes: f_stdcall sets the calling convention -export takes care of name mangling running code in a dll does not bring up the nag screen associated with running .exe files -- Elliot -- e-mail: epc8 at juno dot com |