[GRASS5] Re: contents of grass5 digest, Vol 1 #505, Message: 10

Scott O'Donnell odonnell at fsl.noaa.gov
Wed Oct 9 12:30:40 EDT 2002


Jeshua,

I'm a C++ (GNU/g++, Slackware-8.0 Linux, Intel box) developer and a 
longtime user of GRASS (since the early 4.0 days, at least).

The GRASS list hasn't addressed many of the issues involved in getting 
an application to build using GNU/g++ (C++), AFAICT.  I've recently had 
to resolve some of the problems you are facing when compiling and linking 
GRASS libraries with C++.  Perhaps my experience in this will help you
with your particular problem.

I recently wrote an application to translate some weather radar
reflectivity data into a GRASS raster format to use as input for
another GRASS application.  I wanted to incorporate some of my favorite
C++ utilities as well as make use of the GRASS functions in the
'libgis' library to help me correctly format my radar data.

Because the C++ compiler 'mangles' (changes) the names of symbol
references differently than the 'C' (gcc) compiler, I found that the
following simple construct allowed me to make calls to GRASS library
functions from my C++ application.

In the header section of the source code file (or better in a header
file), wrap the "#include gis.h" declaration with an "extern C"
directive, as in the following example:

extern "C" {
  #include "gis.h"
  }

What this does is to tell the C++ compiler that 'C' naming protocols are
used for these symbols, and allows the linker to find the referenced
functions, data structures, or variables in the 'C' compiled libraries.

You may need to include other header file names in the extern "C" 
directive that also have been compiled using the 'C' compiler, because 
of the name mangling differences between compilers.  


More information about the grass-dev mailing list