[GRASS-user] Setting GRASS environment variable in a C program

rabotin rabotin at supagro.inra.fr
Fri May 21 09:15:15 EDT 2010


Dear all,
i'm trying to access to my grass data without launching an active grass 
session with a c program. I'm encoutering issues with the GRASS 
environment variables definitions.
Here my C script

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern "C" {

#include <grass/config.h>
#include <grass/gis.h>
#include <grass/Vect.h>
#include <grass/glocale.h>
#include <grass/dbmi.h>
}


int main(int argc, char *argv[])
{
    char 
name[GNAME_MAX],gisdbase[GNAME_MAX],location[GNAME_MAX],mapset[GNAME_MAX];
    struct Map_info In;
   
    // Setting the grass environment
    G__setenv("GISDBASE","/home/rabotin/grassdata");
    G__setenv("LOCATION_NAME","Roujan");
    G__setenv("MAPSET","PERMANENT");
    G__setenv("MAPSET","simon9");

  
    G_gisinit(argv[0]);
    std::cout << G_getenv(G_gisdbase()) << std::endl;
    std::cout << G_getenv(G_location()) << std::endl;
    std::cout << G_getenv(G_mapset()) << std::endl;
}

When launshing this script in command terminal (outside an active grass 
session), I've got a segmentation fault.

Does anybody try to access grassdata with C program without launching a 
grass session ? And does anybody can share with me the solutions he 
found to solve same issues ?

Thanks in advance

Michael Rabotin

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

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

Laboratoire d'étude des Interactions Sol, Agrosystème et Hydrosystème
UMR LISAH SupAgro-INRA-IRD
Bat. 24
2 place Viala
34060 Montpellier cedex 1 
FRANCE

Téléphone :  33 (0)4 99 61 23 85
Secrétariat : 33 (0)4 99 61 22 61
Fax : 33 (0)4 67 63 26 14
E-mail : rabotin at supagro.inra.fr

*********************************



More information about the grass-user mailing list