[R] rgdal under windows?
blh at mssl.ucl.ac.uk
Tue Aug 24 11:11:18 CEST 2004
I'm pleased to inform that Roger's recipe worked a treat for compiling
rgdal_0.2-7 in conjunction with gdal-1.2.1 and proj-4.4.8. Using
MinGW-3.1.0 with MYS-1.0.8 on an xp pro box (SP1) Proj-4 compiled straight
out of the box. Gdal needed a couple of minor tweaks wrt how the boolean
type is defined. I suspect that gcc is being strict about name spaces. My
hack was an explicit typedef in jpeglib.h: typedef unsigned char boolean;
and to comment out the definition in jmorecfg.h
After that it was plain sailing except for the curious behaviour of the
MinGW dlltool.exe which refused to to pick up R.dll unless it was given the
full path _irrespective_ of what was placed in $PATH.
Big thanks to Roger and Brian for their helpful advice. Complicated? Not if
you learn to read!
From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
Sent: 19 August 2004 19:27
To: Prof Brian Ripley
Cc: Benjamin Lloyd-Hughes; r-help at stat.math.ethz.ch
Subject: Re: [R] rgdal under windows?
On Thu, 19 Aug 2004, Prof Brian Ripley wrote:
> On Thu, 19 Aug 2004, Benjamin Lloyd-Hughes wrote:
> > Has anyone had any joy getting the rgdal package to compile under
> First you need to meet the system requirements:
> SystemRequirements: GDAL library from
> Since that has build instructions which say
> GDAL can be built on Windows using MS VC++ 6.x and MS Visual Studio .NET
> (C++) at the DOS command line.
> you will first need to get a copy of DOS and those compilers. (I suspect
> they mean the Windows command prompt, but they don't seem to know the
> difference which is not confidence-inspiring. I also suspect they mean
> `or' not `and'.) Then you will have to fathom out how to link against a
> VC++ DLL which since this C++ is very unlikely to work with MinGW. So you
> probably need to make the package's rgdal.dll under VC++ -- see
> I have tried and failed to make GDAL with MinGW.
> > I've been trying with MinGW using Duncan Murdoch's Rtools but to no
> Do read README.packages and follow the advice at the top. You don't have
> the (mis-attributed) tools in your path. But that is probably the least
> of your potential problems.
Exactly. The closest anyone has got so far is Hisaji Ono, who used MSYS
(http://www.mingw.org/) to build PROJ.4 and GDAL (GDAL depends on PROJ.4,
PROJ.4 needs a PATH to metadata files for projection and transformation),
and then hand-pasted the paths to the GDAL headers and library into
src/Makevars, running Rcmd INSTALL rgdal at the Windows command prompt as
usual. All of this can be repeated, but is not portable, and does not suit
the very valuable standard binary package build system for Windows.
1. Download everything you need to build source packages under Windows and
make sure it works;
2. Download MSYS and make sure it works;
3. Download the GDAL and PROJ.4 source tarballs, and possibly other
libraries you want to use with GDAL, and *within MSYS* untar, ./configure
with the appropriate arguments, at least make but maybe also make install
- now leave MSYS;
4. Download the rgdal source package, and *at the Windows command prompt*
untar it, change the name of configure to something else, create
src/Makevars manually from src/Makevars.in, insert the correct values of:
PKG_CPPFLAGS as -I<path to the directory with the GDAL headers>, PKG_LIBS
as -L< ... GDAL libraries> -lgdal, run Rcmd INSTALL rgdal (better first
Rcmd check rgdal), and repeat until all the problems are resolved.
5. The installation should work locally, but some paths are compiled into
the resulting *.dll, so it will, most likely, not be portable.
Both Hisaji and I were surprised that this actually seemed to work (as of
late Autumn last year for the versions of MinGW and MSYS available then;
further fragility is introduced by much of GDAL being written in C++); it
is not wholly impossible that it could be made available portably as a
Windows binary with an installer, but not through the regular R binary
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help