[GRASS-dev] Error in previous declaration when compiling

Dear All,
Using GRASS to develop shell and perl script during few years, I try to develop now my own scripts in C and C++ and using the grass library.

We are using an modelisation platform environment (where my scripts will be implemented) which use the libglibmm library (on ubuntu 64 bits).

When I try this liitle script in C++:

#include <module.h>

extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/Vect.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>

}

int main()
{

return 0;
}

Where module.h is a header file of the libglibmm library, GCC returns the following errors with the following command:

gcc -c main.cpp -I/usr/lib/grass64/include/ -I/usr/include/gdal -I/usr/include/glibmm-2.4/glibmm/

In file included from main.cpp:14:0:
/usr/lib/grass64/include/grass/gis.h:623:8: error: using typedef-name ‘GModule’ after ‘struct’
/usr/include/glibmm-2.4/glibmm/module.h:30:38: error: ‘GModule’ has a previous declaration here
In file included from /usr/lib/grass64/include/grass/gis.h:645:0,
from main.cpp:14:
/usr/lib/grass64/include/grass/gisdefs.h:886:8: error: using typedef-name ‘GModule’ after ‘struct’
/usr/include/glibmm-2.4/glibmm/module.h:30:38: error: ‘GModule’ has a previous declaration here
/usr/lib/grass64/include/grass/gisdefs.h:886:38: error: invalid type in declaration before ‘;’ token

It seems that grass/gis.h and the libgilbmm librarys declare a structure with the same name: GModule.
As I am steel a newbie in C and C++ developments, I don't really know how to solve this problem. Does anyone meet the same issues when using independant library with grass libraries ?

Thanks for any help

Michael Rabotin

--
*********************************

Michaël Rabotin
Ingénieur d'étude en géomatique / GIS Engineer

Laboratoire d'étude des Interactions Sol, Agrosystème et Hydrosystème

UMR LISAH Montpellier SupAgro-INRA-IRD
Bat. 24
2 place Viala
34060 Montpellier cedex 1
FRANCE

Laboratory Interactions between Soils, Agrosystems and Hydrosystems (LISAH)
Multi-Institute Research Unit (UMR)
French National Institute for Agricultural Research (INRA)
French Institute for Research and Overseas Development (IRD)
International Center for Higher Education in Agricultural Sciences (Montpellier SupAgro)

Téléphone / Phone number : 33 (0)4 99 61 23 85
Secrétariat / Secretariat : 33 (0)4 99 61 22 61
Fax : 33 (0)4 67 63 26 14
E-mail : rabotin@supagro.inra.fr
Site web / website: http://www.umr-lisah.fr/
Site web OpenFLUID / OpenFLUID website: http://www.umr-lisah.fr/openfluid/
*********************************

rabotin wrote:

It seems that grass/gis.h and the libgilbmm librarys declare a structure
with the same name: GModule.
As I am steel a newbie in C and C++ developments, I don't really know
how to solve this problem.

It might work to use e.g.:

  #define GModule GRASS_GModule
  #include <grass/gis.h>
  #include <grass/Vect.h>
  #include <grass/dbmi.h>
  #include <grass/glocale.h>
  #undef GModule

You'll need to use GRASS_GModule when declaring the variable to hold
the pointer returned from G_define_module().

Note that you can't do it the other way around (change the name used
by glibmm) because type names are embedded in external symbols which
have C++ linkage.

I was going to suggest that gtkmm should be using C++ namespaces, but
it already does; GModule comes from glib itself.

I'm guessing that GRASS uses GModule because Module caused a conflict
sometime in the past (Flag and Option aren't called GFlag or GOption).

The "G" prefix is a bit unfortunate really, given how many libraries
use it (usually from GNU; e.g. GNU Image Manipulation Program (GIMP)
-> GIMP ToolKit (GTK) -> gtk/gdk/glib -> gtkmm/glibmm).

--
Glynn Clements <glynn@gclements.plus.com>