[Gdal-dev] Windows linking to FWTools gdal_i.lib

Roger Bivand Roger.Bivand at nhh.no
Wed Feb 15 11:02:15 EST 2006


In revising and extending the R GDAL bindings, I'm using VC++ (cl) under 
Windows on C API files. On Linux (GDAL 1.3.1) the references to:

OSRNewSpatialReference
OSRDestroySpatialReference
OSRExportToProj4
OSRExportToWkt

are found and work, but give error LNK2019 in the Windows linking step
when building the rgdal shared object, using Windows binary
FWTools1.0.0.7a gdal_i.lib. The LNK2019 error message prepends an
underscore to the function names. Curiously, it does not report that other
OSR* functions are not found in this function:

#include <R.h>
#include <Rinternals.h>
#include <Rdefines.h>

#include "ogr_api.h"

SEXP p4s_to_wkt(SEXP p4s, SEXP esri) {

    OGRSpatialReferenceH hSRS = NULL;
    char *pszSRS_WKT = NULL;
    SEXP ans;

    hSRS = (OGRSpatialReferenceH) OSRNewSpatialReference(NULL);
    if (OSRImportFromProj4(hSRS, CHAR(STRING_ELT(p4s, 0))) != OGRERR_NONE)
	error("Can't parse PROJ.4-style parameter string");
    if (INTEGER_POINTER(esri)[0] == 1) OSRMorphToESRI(hSRS);
    OSRExportToWkt(hSRS, &pszSRS_WKT);

    PROTECT(ans=NEW_CHARACTER(1));
    SET_STRING_ELT(ans, 0, COPY_TO_USER_STRING(pszSRS_WKT));

    OSRDestroySpatialReference(hSRS);
    UNPROTECT(1);

    return(ans);
}

but that could be because it gave up too soon. Is the GDAL build for 
FWTools not exporting some functions in the gdal_i.lib? 

The rgdal R package has some source files in C++, some in C, and I had 
intended to migrate to the C API. The equivalent C++ functions, like 
*.importFromProj4 and *.exportToWkt are found (or at least link doesn't 
complain.

The only message during the cl compile step was:

...\include\cpl_config.h(75) : warning C4068 : unknown pragma

refering to:

#pragma warning(disable: 4786)

but I don't know that this has any relevance, and is reported both for C 
and C++ files (for the include\cpl_config.h in FWTools1.0.0.7a).

I can put up the problem files on the rgdal CVS if that would help, but 
maybe this is a well-known problem?

I can also make an R-less C source file just to test this, if it would be 
useful.

Telling Windows users simply to install FWTools, put the FWTools/bin in
their PATH, and install the Windows binary rgdal package within R is much
easier than other options. It did work before I added spatial references,
but they are needed. We've tried MSYS and MinGW, which works, but is a
waste of effort when a fair number of thw Windows users have (or should
have) FWTools anyway. Reading OGR now works too, so leveraging off
GDAL/OGR is a very good way of doing things provided I sort out how to do
it portably ...

Best wishes,

Roger

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the Gdal-dev mailing list