Admittedly, cross-compiling a threaded interactive GUI based program (based on Unix libraries not intended for porting to Windows) is substantially more complex, and I haven't done that. But I think just compiling a conforming program in a standardized language is still useful and interesting for some users, and deserves appropriate documentation.
I believe the same procedure would be effective for any of the languages in the GNU compiler suite for any recent rpm based distribution, but I have only worked with Fortran. At the end of the page I report the procedures for Debian-derived and FreeBSD systems.
# yum install mingw32-gcc-fortranor the entire suite including Objective-C, Java and numerous Unix-C specific libraries and development tools.
# yum install mingw32\*
but the later is almost 400 megabytes against less than 100 megabyes for the subset, and not much of the later is relevant for fortran.
The MinGW compilers are the same as the compilers in the GNU compiler suite, except that they have "i686-pc-mingw32-" prepended to the command name and they link to Windows compatible libraries. The prepend string is defined by the particular Linux distribution and this particular string value is RedHat-specific and subject to change. If your computer doesn't respond to that name, you can probably locate the command names in /usr/bin or nearby. But at this time with Fedora 11 one can compile the f77 program "hello.for" with:
%> i686-pc-mingw32-gfortran -o hello.exe -static hello.for
The options are passed to the GNU compiler, any you require on Linux you will likely want to keep on Windows where they should have the same effect. The -static option is a simple way to make calls to DLLs resolve in Windows or Wine. Alternatively you could copy the MingGW DLLs to an appropriate directory, or (in the case of Wine) follow the instructions here. But I haven't tried either of those, since -static is so much easier for me and my user. If you omit the -o argument, you get "a.exe" as the name of the Windows executable.
# yum install wine -yand run the test with:
%> wine hello.exe
With the default wine configuration you need the explicit ".exe" or you get an "unsupported architecture" error message. It isn't necessary in a real windows system.
I found no unexpected system dependencies compiling my often ported (but 21,000 lines) program. As desired:
I used the FreeBSD 7.2 CD-ROM dated May 2009.
su cd /usr/ports/devel/mingw32-gcc make NO_CHECKSUM=YES ming32-gfortran -static -o hello.exe hello.for cd /usr/ports/emulators/wine make wine hello.exe
The NO_CHECKSUM option may not be required if your ports tree has the correct distinfo file. There are 5 other pieces to the MinGW32 system in the devel directory, all begin "mingw32".
I used the Ubuntu 9.04 CD-ROM and started with:
sudo apt-get inwstall mingw32\*but that package did not include the fortran frontend. A bit of searching around the net turned up the somewhat older "Speedblue" package:
sudo apt-get install mingw32-g77-speedblue /usr/i586-mingw32/bin/i586-mingw32-g77 -static -o hello.exe hello.for wine hello.exe
Surprisingly, the Speedblue executables are placed out of the standard path. The g77 compiler is an older fortran 77 compilter that has few of the fortran 95 features that are included in gfortran, but is still of high quality if you have conforming code.
22 September 2009