[GRASS-user] Call Grass modules from C++ code
Vaclav Petras
wenzeslaus at gmail.com
Sun Feb 17 05:31:15 PST 2013
On 16 February 2013 00:42, matteo poletti <pollo1_91 at yahoo.it> wrote:
>> Da: Hamish <hamish_b at yahoo.com>
>
>> have a look at the functions in lib/gis/spawn.c.
>
> Ok, so if I got it right I need to do a sys call exec. What do you usually do for reading the module's output?
>
I hope this will help:
http://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c
If you are using some framework such as Qt, you can use the way used
in this framework.
> I suppose that, doing the things this way, I'll need to run my program inside a grass shell to have it working.
Yes, you always need to run your program (which uses lib or modules)
in grass session. Your program is in fact a grass module. However,
there is an alternative -- to set up some environment variables (most
recently discussed in thread "Bash aliases in GRASS").
http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly
>
> Do I need the "extern" keyword in this case? I guess not since I'm doing a sys call.
Exactly, "extern" is necessary to properly include function declarations.
Best,
Vaclav
BTW, I would ask this question on grass-dev. For me, it is more
developer than user question because of C++.
>
> Maybe I've misunderstood the example...
> Thanks!
> Matteo
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
More information about the grass-user
mailing list