GRASS and C++: Difference between revisions
(+GRASS Programmer's Manual) |
|||
(4 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
I/O: | I/O: | ||
* | * {{src|lib/iostream/}} | ||
Raster data processing | Raster data processing | ||
* | * {{src|raster/r.terraflow/}} | ||
Image processing | Image processing | ||
* | * {{src|imagery/i.atcorr/}} | ||
Visualization: | Visualization: | ||
* | * {{src|visualization/xganim/}} | ||
* | * {{src|visualization/wximgview/}} | ||
== Notes == | == 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: | |||
<source lang="c"> | <source lang="c"> | ||
extern "C" | #ifdef __cplusplus | ||
{ | extern "C" { | ||
# | #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).