[GRASSLIST:2055] Re: basic prgramming question

Eric G. Miller egm2 at jps.net
Wed Jul 4 16:31:54 EDT 2001


On Wed, Jul 04, 2001 at 02:49:44PM -0500, Robert Najlis wrote:
> I am trying to learn how to program GRASS.  I have been looking at the
> tutorial and I am just trying to make sure my system is set uo, etc.
> 
> At this point I am just trying to get started - try a few commands, things
> like that. Actually, right now I am just trying to compile a program that
> only has the line #include "gis.h" just to make sure everything is working
> correctly.  
> 
> It seems that I need to use gmake5 to compile the program. Is this true?
> If so, would someone be kind enough to give me a sample gmake5 Makefile?
> Or any other example of how to compile c code with GRASS commands in it.  

# Name of the program...
PGM=my_test

# Object files (i.e. replace *.c with *.o)
OBJS=main.o

# The compile line.  Pretty much always depend on GISLIB
# And any use of GISLIB must also have $(XDRLIB)
$(PGM): $(GISLIB)
	$(CC) -o $@ $(OBJS) $(GISLIB) $(XDRLIB)
^       ^         ^ ^       ^-----------------^ (libgis, libnsl, libz)
\       \         \  \------------- (object files)
 (tab)   compiler  \ alias for $(PGM)


It's very similar to any other Makefile, but actually quite simplified.
The gmake5 program fills in the details.

Simple program:

#include <stdio.h>
#include <stdlib.h>
#include "gis.h"

int main (int argc, char **argv)
{
	char *gisbase;
	G_gisinit(argv[0]);

	gisbase = G_getenv ("GISBASE");

	fprintf (stdout, "GRASS programs live under \"%s\"\n", gisbase);
	
	return (EXIT_SUCCESS);
}


Note: gmake5 won't be built unless you've built GRASS from sources and
installed it.  Kinda goofy like that...

-- 
Eric G. Miller <egm2 at jps.net>



More information about the grass-user mailing list