GRASS and C++: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(+notes)
(+GRASS Programmer's Manual)
 
(5 intermediate revisions by 3 users not shown)
Line 4: Line 4:


For working examples, see:
For working examples, see:
Digitizer:
* http://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/vdigit/


I/O:
I/O:
* http://trac.osgeo.org/grass/browser/grass/trunk/lib/iostream/
* {{src|lib/iostream/}}


Raster data processing
Raster data processing
* http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.terraflow/
* {{src|raster/r.terraflow/}}


Image processing
Image processing
* http://trac.osgeo.org/grass/browser/grass/trunk/imagery/i.atcorr/
* {{src|imagery/i.atcorr/}}


Visualization:
Visualization:
* http://trac.osgeo.org/grass/browser/grass/trunk/visualization/xganim/
* {{src|visualization/xganim/}}
* http://trac.osgeo.org/grass/browser/grass/trunk/visualization/wximgview/
* {{src|visualization/wximgview/}}


== Notes ==
== Notes ==


When developing C++ code to call a C function you need to specified for the compiler that the gis.h include is C code with:
C++ code that use C shared libraries needs to specify this fact to the compiler. This can be defined with the ''extern "C"'' keyword, in this way:


<source lang="c">
<source lang="c">
extern "C"  
#ifdef __cplusplus
{
extern "C" {
#include <grass/gis.h>
#endif
 
...
 
#ifdef __cplusplus
}
}
#endif
</source>
</source>
The C++ compiler will understand that the functions defined in gis.h are coded in C. If it is not specified the linking step will throw an error stating that the symbols for the C functions were not found in the shared library. Without the 'extern "C" ...' qualification, C++ assumes that functions have C++ linkage, meaning that the parameter types are embedded in the symbol name (C++ allows function overloading, where multiple functions can have the same name provided that they have different parameter types).
== See also ==
* [[GRASS and Python]]
* [http://grass.osgeo.org/programming7/ GRASS 7 Programmer's Manual]


[[Category:Development]]
[[Category:Development]]
[[Category:Linking to other languages]]
[[Category:Linking to other languages]]
[[Category:C++]]
[[Category:C++]]

Latest revision as of 21:06, 27 November 2012

(page to be expanded)

Calling GRASS library functionality in C++

For working examples, see:

I/O:

Raster data processing

Image processing

Visualization:

Notes

C++ code that use C shared libraries needs to specify this fact to the compiler. This can be defined with the extern "C" keyword, in this way:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

The C++ compiler will understand that the functions defined in gis.h are coded in C. If it is not specified the linking step will throw an error stating that the symbols for the C functions were not found in the shared library. Without the 'extern "C" ...' qualification, C++ assumes that functions have C++ linkage, meaning that the parameter types are embedded in the symbol name (C++ allows function overloading, where multiple functions can have the same name provided that they have different parameter types).

See also