[Proj] Compilation under Windows; DLL issues

proj-admin at remotesensing.org proj-admin at remotesensing.org
Thu Apr 15 04:26:15 EDT 2004


Hi all,

There are some issues using libproj as a DLL under Windows.
The way the definitions currently are, it is not possible to access
pj_errno or pj_release.
The reasons for that are:
*) pj_release is not defined as an export in proj.def
*) pj_errno needs __declspec(dllimport) in its declaration to be accessible

The second issue is a tricky one. Methods don't need the __declspec-stuff,
they just get a second level of indirection in the code. Data, however, need
that.



My suggestion:

-------------------------

In makefile.vc, add the define "PROJ_EXPORTS":
CFLAGS = /nologo -I. -DPROJ_LIB=\"$(PROJ_LIB_DIR)\" $(OPTFLAGS) /D
"PROJ_EXPORTS"

--------------------------

In proj_api.h, do the follwing:

#ifdef DLL_API
#undef DLL_API
#endif

#if !defined(WIN32) && defined(PROJ_EXPORTS)
#define DLL_API
#else
#define DLL_API __declspec(dllimport)
#endif

Add DLL_API before each declaration:

DLL_API extern char const pj_release[]; /* global release id string */
...
DLL_API extern int pj_errno;	/* global error return code */
...

DLL_API projXY pj_fwd(projLP, projPJ);
DLL_API projLP pj_inv(projXY, projPJ);

DLL_API int pj_transform( projPJ src, projPJ dst, long point_count, int
point_offset,
                  double *x, double *y, double *z );
DLL_API int pj_datum_transform( projPJ src, projPJ dst, long point_count,
int point_offset,
                        double *x, double *y, double *z );
DLL_API int pj_geocentric_to_geodetic( double a, double ra,
                               long point_count, int point_offset,
                               double *x, double *y, double *z );
DLL_API int pj_geodetic_to_geocentric( double a, double ra,
                               long point_count, int point_offset,
                               double *x, double *y, double *z );
DLL_API int pj_compare_datums( projPJ srcdefn, projPJ dstdefn );
DLL_API int pj_apply_gridshift( const char *, int, 
                        long point_count, int point_offset,
                        double *x, double *y, double *z );
DLL_API void pj_deallocate_grids();
DLL_API int pj_is_latlong(projPJ);
DLL_API int pj_is_geocent(projPJ);
DLL_API void pj_pr_list(projPJ);
DLL_API void pj_free(projPJ);
DLL_API void pj_set_finder( const char *(*)(const char *) );
DLL_API projPJ pj_init(int, char **);
DLL_API projPJ pj_init_plus(const char *);
DLL_API char *pj_get_def(projPJ, int);
DLL_API projPJ pj_latlong_from_proj( projPJ );
DLL_API void *pj_malloc(size_t);
DLL_API void pj_dalloc(void *);
DLL_API char *pj_strerrno(int);
DLL_API int *pj_get_errno_ref();

--------------------------

In proj.def, add pj_release.

--------------------------

Regards
Thomas



More information about the Proj mailing list