I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a Windows Computer

Embed Size (px)

Citation preview

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    1/15

    Cross compiling on Linux/FreeBSD for a Windows target with MinGW32

    I wanted to compile bog-standard Fortran 95 code on a Linux (Fedora 11) system for subsequent

    execution on a Windows computer. This is amazingly easy to do with the MinGW cross compiler suite

    if one knows how, but the documentation is fairly vague on the basics of cross compilation, hence thisposting.

    Admittedly, cross-compiling a threaded interactive GUI based program (based on Unix libraries notintended 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.Step 1. Installing the cross compilers on YUM/RPM based distributions

    You can install just the Fortran, gcc and c++ cross-compilers:

    # yum install mingw32-gcc-fortran

    or the entire suite including Objective-C, Java and numerous Unix-C specific libraries and developmenttools.

    # 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.

    Step 2. Compiling the fortran program

    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 cancompile 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 appropriatedirectory, 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.Step 3. Testing the program

    It is nice to test the program without moving it to another system. If you haven't installed wine:

    # yum install wine -y

    and run the test with:

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    2/15

    %> wine hello.exe

    With the default wine configuration you need the explicit ".exe" or you get an "unsupportedarchitecture" error message. It isn't necessary in a real windows system.

    System dependencies

    I found no unexpected system dependencies compiling my often ported (but 21,000 lines) program. As

    desired:

    * Slashes in filenames need to be changed to backslashes.

    * Formatted writes are terminated with cr/lf.

    * Formatted reads can be terminated with cr/lf or lf alone.

    * I/O units star, zero and six all go to the command console.* Unit zero is not redirectable with ">".

    * I/O unit 1 goes to fort.1.

    * call system("command") executes command in cmd.exe.

    I have not tested portability of unformatted or direct access files.

    Other Unix Distributions

    FreeBSD

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    3/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    4/15

    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.Other references

    http://artificialtime.com/ashaduri/#mingw-notes

    Comments welcome.

    Daniel Feenberg22 September 2009

    [email protected]

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    5/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    6/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    7/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    8/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    9/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    10/15

    ROBERT ADHI

    KUSUMA

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    11/15

    PUTRAtoday we have great leaders who are brave and dashing around 5:00 o'clock in the morning as usual

    they already hurrying named robert adhi ready ready to spin tangerang jakarta son with his car vehicle

    vehicles toyota cadet in the photos around Tangerang and Jakarta to write in a merchant fleet workerstangerang 1000000000000000000 Cikarang Bekasi always follow each one eye movements and brain

    epala the unconscious person is always like a mamantau and oversee Army Intelligence HQ the number

    1 most dangerous because the brain and eat and drink, extraordinary motion pictures thinking around100 000 workers was followed by the computer as bekasi tangerang depok Cikarang

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    12/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    13/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    14/15

  • 8/9/2019 I Wanted to Compile Bog-standard Fortran 95 Code on a Linux (Fedora 11) System for Subsequent Execution on a

    15/15