Skip to content

gfortran Makefile for windows

3 messages · Joel Bremson, Brian Ripley

#
I am unaware that gfortran or gcc4 exist as a MinGW binary for Windows.
You mention Cygwin, but that is not a supported platform for R.

There is a g95 binary for Windows.

You can find how to link on Windows from the sources: most of the rules 
are in src/gnuwin32/MkRules.   I suspect all you need is to set 
pkgname-DLLLIBS appropriately.


I don't see that you need a Makefile: a Makevars file would suffice and 
avoid your hardcoding so many OS-specific features.  In any case it seems 
to me that in general you need to link against the Fortran libraries: you 
may get away with it on MacOS, but you will not on Windows.

Support for F95 files is planned for R 2.3.0, but depends on being able to 
differentiate F77 and F95 sources where needed (most platforms). 
Meanwhile we will try to add an example to the R-admin manual for 2.2.0.
On Wed, 28 Sep 2005, Joel Bremson wrote:

            
Congratulations: you have now read the posting guide and selected an 
appropriate list!  Perhaps soon you will get the part about not sending 
HTML mail?

Seriously, there is a posting guide, and it asks you to do your homework 
before posting.  Please show us the courtesy of doing so.

  
    
#
On Wed, 28 Sep 2005, Prof Brian Ripley wrote:

            
At www.g95.org, but I found no installation instructions relevant to 
Windows.  Some comments at the end of this message.

[...]
Here is an example src/Makefile.win for a package called testf95 that uses 
F95/F90 only.

% cat testf95/src/Makefile.win

DLLNAME=testf95 # will not be needed in 2.2.0

include $(RHOME)/src/gnuwin32/MkRules

F90SOURCES=$(wildcard -f *.f90)
F95SOURCES=$(wildcard -f *.f95)
OBJS=$(F90SOURCES:.f90=.o) $(F95SOURCES:.f95=.o)

G95=c:/packages/g95/bin/g95
MINGW=c:/packages/gcc-3.4.4/

.SUFFIXES: .f90 .f95
.f90.o:
 	$(G95) -c $< -o $@
.f95.o:
 	$(G95) -c $< -o $@

## at least on my setup, G95 is not searching MinGW libs.
DLL=$(G95) -L$(MINGW)/lib

all: $(DLLNAME).dll

## Rules copied from MakeDll

RCNAME=${DLLNAME}_res
RCOBJ=$(RCNAME).o
RESFLAGS=--include-dir $(RHOME)/include
$(DLLNAME)_res.rc:
 	@PERL5LIB=$(RHOME)/share/perl perl 
$(RHOME)/src/gnuwin32/makeDllRes.pl $(DLLNAME) > $@
$(DLLNAME)_res.o: $(DLLNAME)_res.rc $(RHOME)/include/Rversion.h
$(DLLNAME).a: $(OBJS)
$(DLLNAME).dll : $(DLLNAME).a $(RCOBJ)


It works for me, but do be aware that it will depend on the
fine details of how your MinGW/G95 tools are installed.  I had to copy
dllcrt2.o from MINGW/lib to
C:/packages/g95/lib/gcc-lib/i686-pc-mingw32/4.0.1 since the paths are
processed after that file.  It is probably better to fiddle with the specs 
file.