Difference between revisions of "F2c"

From Computer History Wiki
Jump to: navigation, search
(New page: While not really a compiler, f2c is based on the UNIX FORTRAN compiler, but as it used the same backend as the C compiler, f2c emits C, which in turn can be compiled by the nat...)
 
(Add a clearer brief description of what it is; use canonical CHWiki article format)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
While not really a compiler, f2c is based on the [[UNIX]] [[FORTRAN]] compiler, but as it used the same backend as the [[C]] compiler, f2c emits C, which in turn can be compiled by the native compiler.
+
'''f2c''' is 'sort of' a [[FORTRAN]] [[compiler]]. Technically, it is not really a compiler, as it does not produce [[object code]]; rather, it emits [[C (language)|C]] [[source]], which in turn can be compiled by a native C compiler.
  
F2C can be downloaded from http://www.netlib.org/f2c/
+
It is based on the [[UNIX]] FORTRAN compiler, but it used the same backend as the C compiler.  
  
== installing ==
+
== Installing ==
F2c is easy to install, you can download the source here: http://vpsland.superglobalmegacorp.com/install/f2c/f2c.tar.gz
+
 
 +
f2c will build for [[MS-DOS]] (DPMI), [[Win32]], and most UNIX systems. The biggest issue I've had testing has been the [[DEC Alpha]] because its [[floating point]] seems to be too different.
 +
 
 +
f2c is somewhat straightforward to install... The two big 'camps' are Unix and [[Windows]].
 +
 
 +
=== Unix/MinGW ===
 +
 
 +
For UNIX systems it's easier to install tar.gz's (below). An additional squashfs backup has been placed on archive.org (also below). Simply extract and run:
  
Simply extract and run:
 
 
<pre>
 
<pre>
make -f makefile.u
+
tar -zxvf f2c.tar.gz
 +
cd f2c
 +
make -f makefile.u f2c
 
</pre>
 
</pre>
  
Line 19: Line 27:
 
If all went well you should have a f2c command.
 
If all went well you should have a f2c command.
  
Next you'll need to download and build the IO library http://vpsland.superglobalmegacorp.com/install/f2c/libf2c.zip
+
Next you'll need to download and build the IO library  
  
 
Simply extract and run:
 
Simply extract and run:
 
<pre>
 
<pre>
 +
tar -zxvf libf2c.tar.gz
 +
cd libf2c
 
make -f makefile.u
 
make -f makefile.u
 
</pre>
 
</pre>
Line 30: Line 40:
 
cp libf2c.a /usr/local/lib
 
cp libf2c.a /usr/local/lib
 
</pre>
 
</pre>
 +
 +
=== Visual C++/MS-DOS ===
 +
 +
f2c can also be built using [[Visual C++]].  The key here is that you'll have to use the .vc makefiles.
 +
For Windows/MS-DOS users it's easier to download the zip files (below), and then simply unzip f2c.zip somewhere, then using the CLI tools simply:
 +
 +
<pre>
 +
cd f2c
 +
nmake -f makefile.vc f2c.exe
 +
</pre>
 +
 +
This will build the f2c translator.  You may wish to copy it somewhere in your path, along with the f2c.h into your include path.
 +
 +
Next is the IO library.
 +
 +
<pre>
 +
nmake -f makefile.vc
 +
</pre>
 +
 +
This will now generate the vcf2c.lib which you'll need to link your programs against.
 +
 +
== Test program ==
  
 
Now you should be able to build a simple FORTRAN program like this:
 
Now you should be able to build a simple FORTRAN program like this:
Line 35: Line 67:
 
hello.f
 
hello.f
 
<pre>
 
<pre>
 +
C1234567890
 +
C    Hello world
 
       program hello  
 
       program hello  
 
       print *, 'Hello!'  
 
       print *, 'Hello!'  
 
       end
 
       end
 +
 
</pre>
 
</pre>
 +
 +
Note that you'll need a blank line on the end.  This just makes f2c all the happier.
 +
 +
=== Build instructions for Unix ===
  
 
Then run:
 
Then run:
Line 52: Line 91:
 
</pre>
 
</pre>
  
 +
=== Build instructions for Windows ===
 +
 +
<pre>
 +
c:\temp\x>f2c\f2c hello.f
 +
hello.f:
 +
  MAIN hello:
 +
 +
c:\temp\x>cl hello.c -If2c libf2c\vcf2c.lib
 +
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
 +
Copyright (C) Microsoft Corporation.  All rights reserved.
 +
 +
hello.c
 +
Microsoft (R) Incremental Linker Version 9.00.21022.08
 +
Copyright (C) Microsoft Corporation.  All rights reserved.
 +
 +
/out:hello.exe
 +
hello.obj
 +
libf2c\vcf2c.lib
 +
 +
c:\temp\x>hello
 +
Hello!
 +
</pre>
 +
 +
Naturally if you copy the f2c.h file into your include path, and the vcf2c.lib into your libpath then you won't have to directly path to them....  But I think this should get you going.
 +
 +
== Programs that build with f2c ==
 +
 +
I'm not that big into FORTRAN, but here is a small list of programs that I've built with f2c.
 +
 +
* [[Dungeon]] (version 2.5.6 works great!)
 +
* [[Snoopy Calendar]]
 +
 +
==External links==
 +
 +
* [http://www.netlib.org/f2c/ netlib/f2c] - download
 +
* UNIX system downloads:
 +
** [http://vpsland.superglobalmegacorp.com/install/f2c/f2c.tar.gz f2c.tar.gz]
 +
** [http://vpsland.superglobalmegacorp.com/install/f2c/libf2c.tar.gz libf2c.tar.gz]
 +
** [https://archive.org/details/f2c_20240618 f2c files from vpsland] - an additional squashfs backup
 +
* Windows/MS-DOS system downloads:
 +
** [http://vpsland.superglobalmegacorp.com/install/f2c/f2c.zip f2c.zip]
 +
** [http://vpsland.superglobalmegacorp.com/install/f2c/libf2c.zip libf2c.zip]
  
{{stub}}
+
[[Category: Fortran Compilers]]
[[Category:Compilers]]
 

Latest revision as of 16:37, 21 June 2024

f2c is 'sort of' a FORTRAN compiler. Technically, it is not really a compiler, as it does not produce object code; rather, it emits C source, which in turn can be compiled by a native C compiler.

It is based on the UNIX FORTRAN compiler, but it used the same backend as the C compiler.

Installing

f2c will build for MS-DOS (DPMI), Win32, and most UNIX systems. The biggest issue I've had testing has been the DEC Alpha because its floating point seems to be too different.

f2c is somewhat straightforward to install... The two big 'camps' are Unix and Windows.

Unix/MinGW

For UNIX systems it's easier to install tar.gz's (below). An additional squashfs backup has been placed on archive.org (also below). Simply extract and run:

tar -zxvf f2c.tar.gz
cd f2c
make -f makefile.u f2c

Then run:

cp f2c /usr/local/bin
cp f2c.h /usr/local/include

If all went well you should have a f2c command.

Next you'll need to download and build the IO library

Simply extract and run:

tar -zxvf libf2c.tar.gz
cd libf2c
make -f makefile.u

Then run:

cp libf2c.a /usr/local/lib

Visual C++/MS-DOS

f2c can also be built using Visual C++. The key here is that you'll have to use the .vc makefiles. For Windows/MS-DOS users it's easier to download the zip files (below), and then simply unzip f2c.zip somewhere, then using the CLI tools simply:

cd f2c
nmake -f makefile.vc f2c.exe

This will build the f2c translator. You may wish to copy it somewhere in your path, along with the f2c.h into your include path.

Next is the IO library.

nmake -f makefile.vc

This will now generate the vcf2c.lib which you'll need to link your programs against.

Test program

Now you should be able to build a simple FORTRAN program like this:

hello.f

C1234567890
C    Hello world
      program hello 
      print *, 'Hello!' 
      end

Note that you'll need a blank line on the end. This just makes f2c all the happier.

Build instructions for Unix

Then run:

bash-2.01$ f2c hello.f 
hello.f: 
   MAIN hello: 
bash-2.01$ cc hello.c -lf2c -o hello 
bash-2.01$ file hello 
hello:  Mach-O executable (for architecture m68k) not stripped 
bash-2.01$ ./hello 
Hello!

Build instructions for Windows

c:\temp\x>f2c\f2c hello.f
hello.f:
   MAIN hello:

c:\temp\x>cl hello.c -If2c libf2c\vcf2c.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hello.exe
hello.obj
libf2c\vcf2c.lib

c:\temp\x>hello
 Hello!

Naturally if you copy the f2c.h file into your include path, and the vcf2c.lib into your libpath then you won't have to directly path to them.... But I think this should get you going.

Programs that build with f2c

I'm not that big into FORTRAN, but here is a small list of programs that I've built with f2c.

External links