[gdal-dev] Re: Link GDAL with MinGW

LF lucafasano at interfree.it
Thu Feb 26 12:08:51 EST 2009


Frank Warmerdam <warmerdam <at> pobox.com> writes:

> 
> Ari Jolma wrote:
> > oops, I believe it is not correct to say "Swig bindings use some C++ 
> > API", but it is nevertheless sometimes hard/not possible to mix VC and 
> > MinGW when developing for Windows
> 
> Folks,
> 
> I am interested in making use of the GDAL and OGR C API practical and even
> convenient when GDAL is built with MSVC and applications are built with
> MinGW.  If there is a particular problem with this, I would encourage
> filing a ticket.
> 
> Best regards,

First of all, thanks to your fast answers.
Then, I report following my makefile.


GDAL_ROOT="C:\gdalwin32-1.6_bin\"

LD_SHARED=g++ -shared
OBJ=hdf5dataset.o hdf5imagedataset.o
GDAL_INCLUDE=-I "C:\gdal_1_6_0_DEV\include"
HDF5_INCLUDE=-I "C:\5-168-win-vnet_corrected_for_MinGW\include"
CPPFLAGS:=-Wall -fPIC $(GDAL_INCLUDE) $(CPPFLAGS) $(HDF5_INCLUDE)
CPPFLAGS:= -DWIN32 -DDLL_EXPORT -DPIC $(CPPFLAGS)

# Comment out for release mode
CPPFLAGS:=-g3 -ggdb3 -DDEBUG $(CPPFLAGS)
LNK_FLAGS:=$(LNK_FLAGS) -L "C:\gdalwin32-1.6_bin\bin"
#both msvcr inserted 71 and 90
LNK_FLAGS:=$(LNK_FLAGS) -lgdal16 -lmsvcr71 -lmsvcr91
LNK_FLAGS:=$(LNK_FLAGS) -L "C:\5-168-win-vnet_corrected_for_MinGW\dll"
LNK_FLAGS:=$(LNK_FLAGS) -lhdf5_cppdll -lhdf5dll -lhdf5_hldll

.PHONY: default plugin clean

PLUGIN = gdal_HDF5.so
default: plugin
clean:
	rm -f *.o *~ $(PLUGIN)

hdf5dataset.o: hdf5dataset.h
hdf5imagedataset.o: hdf5dataset.h
plugin: $(PLUGIN)
$(PLUGIN):	$(OBJ)
	$(LD_SHARED) $(OBJ) $(LNK_FLAGS) -o $



When I compile my code with MinGW it's all OK, but when MinGW starts 
linking it doesn't found all methods of GDALDataset giving me "undefined
reference" to them. It seems not to link gdal dll.

You can try it in gdalsrc/frmts/hdf5 because it needs three source files in this
folder.

PS. To avoid compiling errors I re-compiled hdf5 as described here:
http://lists.osgeo.org/pipermail/gdal-dev/2007-April/012825.html  and modified
/hdf5/include/H5pubconf.h defining H5_SIZEOF_SSIZE_T:
     #define H5_SIZEOF_SSIZE_T  4 /* for 32 bit machines */
(as described here
http://trac.nexusformat.org/code/browser/branches/4.1/README.MinGW?rev=998)

PS2. I tried to convert gdal dll into a .a file for MinGW as described here:
http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs but it doesn-t link correctly.


Best regards
Luca



More information about the gdal-dev mailing list