Link GDAL with MinGW

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Link GDAL with MinGW

Luca Fasano
Hi to everyone,
I'm trying to make a plugin for GDAL. So I need to use some GDALDataset methods
(AddBand, GetDriver, setGCPs, ...).
When I compile my code with MinGW it's all OK, but when MinGW starts linking it
doesn't found these methods and give me "undefined reference" to all them.
In makefile I added to LNK_FLAGS variable both gdal16.dll and its path. I tried
to use gdal_i.lib of 1.5 version too, but nothing appened.
If it's useful I copy CPP_FLAGS following:

CPPFLAGS:=-Wall -DCSK_PLUGIN -fPIC $(GDAL_INCLUDE) $(HDF5_INCLUDE) $(CPPFLAGS)
CPPFLAGS:= -DH5_HAVE_HIGH_LEVEL_API $(CPPFLAGS)
CPPFLAGS:= -DWIN32 -DDLL_EXPORT -DPIC $(CPPFLAGS)


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link GDAL with MinGW

Ari Jolma
MinGW gcc generates .dll.a files, which are the link libraries, but it
can also use the plain dll to link against.

However, when you mention gdal16.dll, it sounds like you're trying to
link against a GDAL dll that was generated with VC. The C++ API is very
difficult to use from such dll when you're developing with MinGW if not
impossible. I, for one, have never succeeded. The Swig bindings use some
C++ API, which have so far prevented me from using "an official" binary
gdal dll for the Perl bindings for example.

Ari

LF kirjoitti:

> Hi to everyone,
> I'm trying to make a plugin for GDAL. So I need to use some GDALDataset methods
> (AddBand, GetDriver, setGCPs, ...).
> When I compile my code with MinGW it's all OK, but when MinGW starts linking it
> doesn't found these methods and give me "undefined reference" to all them.
> In makefile I added to LNK_FLAGS variable both gdal16.dll and its path. I tried
> to use gdal_i.lib of 1.5 version too, but nothing appened.
> If it's useful I copy CPP_FLAGS following:
>
> CPPFLAGS:=-Wall -DCSK_PLUGIN -fPIC $(GDAL_INCLUDE) $(HDF5_INCLUDE) $(CPPFLAGS)
> CPPFLAGS:= -DH5_HAVE_HIGH_LEVEL_API $(CPPFLAGS)
> CPPFLAGS:= -DWIN32 -DDLL_EXPORT -DPIC $(CPPFLAGS)
>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>  


--
Prof. Ari Jolma
Environmental Management Information Technology
Teknillinen Korkeakoulu / Helsinki University of Technology
tel: +358 9 4511 address: POBox 5300, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://geoinformatics.tkk.fi

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link GDAL with MinGW

Ari Jolma
In reply to this post by Luca Fasano
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

Ari

Ari Jolma kirjoitti:

> MinGW gcc generates .dll.a files, which are the link libraries, but it
> can also use the plain dll to link against.
>
> However, when you mention gdal16.dll, it sounds like you're trying to
> link against a GDAL dll that was generated with VC. The C++ API is
> very difficult to use from such dll when you're developing with MinGW
> if not impossible. I, for one, have never succeeded. The Swig bindings
> use some C++ API, which have so far prevented me from using "an
> official" binary gdal dll for the Perl bindings for example.
>
> Ari
>
> LF kirjoitti:
>> Hi to everyone,
>> I'm trying to make a plugin for GDAL. So I need to use some
>> GDALDataset methods
>> (AddBand, GetDriver, setGCPs, ...).
>> When I compile my code with MinGW it's all OK, but when MinGW starts
>> linking it
>> doesn't found these methods and give me "undefined reference" to all
>> them.
>> In makefile I added to LNK_FLAGS variable both gdal16.dll and its
>> path. I tried
>> to use gdal_i.lib of 1.5 version too, but nothing appened.
>> If it's useful I copy CPP_FLAGS following:
>>
>> CPPFLAGS:=-Wall -DCSK_PLUGIN -fPIC $(GDAL_INCLUDE) $(HDF5_INCLUDE)
>> $(CPPFLAGS)
>> CPPFLAGS:= -DH5_HAVE_HIGH_LEVEL_API $(CPPFLAGS)
>> CPPFLAGS:= -DWIN32 -DDLL_EXPORT -DPIC $(CPPFLAGS)
>>
>>
>> _______________________________________________
>> gdal-dev mailing list
>> [hidden email]
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>  
>
>


--
Prof. Ari Jolma
Environmental Management Information Technology
Teknillinen Korkeakoulu / Helsinki University of Technology
tel: +358 9 4511 address: POBox 5300, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://geoinformatics.tkk.fi

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link GDAL with MinGW

Luca Fasano
In reply to this post by Ari Jolma
Ari Jolma <ari.jolma <at> tkk.fi> writes:
>
> MinGW gcc generates .dll.a files, which are the link libraries, but it
> can also use the plain dll to link against.
>
> However, when you mention gdal16.dll, it sounds like you're trying to
> link against a GDAL dll that was generated with VC. The C++ API is very
> difficult to use from such dll when you're developing with MinGW if not
> impossible.
I'm not sure of this. In the same project I linked *correctly* hdf5 library,
which is a dll file and I think compiled with VC.
I've problem only with gdal.

Perhaps it needs some flags when compile.
>
> Ari
>
> LF kirjoitti:
> > Hi to everyone,
> > I'm trying to make a plugin for GDAL. So I need to use some GDALDataset
methods
> > (AddBand, GetDriver, setGCPs, ...).
> > When I compile my code with MinGW it's all OK, but when MinGW starts
linking it
> > doesn't found these methods and give me "undefined reference" to all them.
> > In makefile I added to LNK_FLAGS variable both gdal16.dll and its path.

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Re: Link GDAL with MinGW

Ari Jolma
LF kirjoitti:

> Ari Jolma <ari.jolma <at> tkk.fi> writes:
>  
>> MinGW gcc generates .dll.a files, which are the link libraries, but it
>> can also use the plain dll to link against.
>>
>> However, when you mention gdal16.dll, it sounds like you're trying to
>> link against a GDAL dll that was generated with VC. The C++ API is very
>> difficult to use from such dll when you're developing with MinGW if not
>> impossible.
>>    
> I'm not sure of this. In the same project I linked *correctly* hdf5 library,
> which is a dll file and I think compiled with VC.
> I've problem only with gdal.
>
> Perhaps it needs some flags when compile.
>  

But you do use VC compiled GDAL DLL? HDF5 seems to be available in many
formats (for cygwin, vs2005, etc). I'm just looking at a hdf5dll.dll and
it does not export anything in C++, while gdal16.dll does. I believe gcc
is not able to decrypt the way VC exports C++ methods, which you are using.

Why don't you use the GDAL DLL that you get from compiling it with MinGW?

Ari
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link GDAL with MinGW

Frank Warmerdam
In reply to this post by Ari Jolma
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,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link GDAL with MinGW

Luca Fasano
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

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Re: Link GDAL with MinGW

Frank Warmerdam
LF wrote:
> 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

Luca,

I get the impression you are trying to build the HDF5 plugin with MinGW
for use with a GDAL built with MSVC.  Plugins use the C++ API and are
generally not going to be compatible between compilers.  At this time
I believe you just have to use a similar compiler to build plugins as
was used to build the core GDAL library.

The offer to improve MinGW/MSVC mixing only applies to the GDAL/OGR C API
(not the C++ API) and is mainly aimed at making it possible to build
applications against the GDAL/OGR C API using MinGW when GDAL is built with
MSVC.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev