[GRASS-dev] Building a new module for GRASS6.2.3

Thank you very much! How can I edit the raster example to have a c++ source code (.cc extension)?
I should edit something in the makefile, but I don't how to do. Someone could help me?

Best regards,

Roberto

On 28/03/08 17:20, roberto caselli wrote:
> *Hello everyone, I have to build a new module for GRASS, but I have*
> *some doubts about what the things I have to do.*
>
> *First of all, i'd need some data structure like graphs, union finds*
> *and dynamic trees. Are these structure included in GRASS?*
>
> *For a beginner like me a guide that explains the building of a module*
> *(or a pattern)  would be very very helpful. Could you suggest me*
> *something to ease my work?*

[http://trac.osgeo.org/grass/browser/grass/trunk/doc/raster](http://trac.osgeo.org/grass/browser/grass/trunk/doc/raster)
[http://trac.osgeo.org/grass/browser/grass/trunk/doc/vector](http://trac.osgeo.org/grass/browser/grass/trunk/doc/vector)

[http://download.osgeo.org/grass/grass6_progman/](http://download.osgeo.org/grass/grass6_progman/)

Moritz

>
> *Best regards, Roberto*
>
> *------------------------------------------------------------------------*
> *Scopri il Blog di Yahoo! Mail* 
> _<[http://us.rd.yahoo.com/mail/it/taglines/yahoo/ymail/SIG=11djrg460/**http%3A%2F%2Fwww.ymailblogit.com%2Fblog%2F](http://us.rd.yahoo.com/mail/it/taglines/yahoo/ymail/SIG=11djrg460/**http%3A%2F%2Fwww.ymailblogit.com%2Fblog%2F)>:_
> *trucchi, novità, consigli... e la tua opinione!*
>
> 

Scopri il Blog di Yahoo! Mail: trucchi, novità, consigli… e la tua opinione!

roberto caselli wrote:

Thank you very much! How can I edit the raster example to have a c++ source code (.cc extension)?
I should edit something in the makefile, but I don't how to do. Someone could help me?

Add the following line before including the *.make files (e.g. Module.make):

  MOD_OBJS := $(subst .cc,.o,$(wildcard *.cc))

By default, MOD_OBJS is determined based upon the .c files in the
directory.

Rules.make already includes pattern rules for compiling .cc and .cpp
files.

Note that the GRASS headers don't make allowances for use in C++ code,
so you need to use e.g.:

  extern "C" {
  #include <grass/gis.h>
  }

At some point, we should probably change Rules.make to automatically
deal with C++ files (.cc and .cpp extensions; maybe .cxx as well).

--
Glynn Clements <glynn@gclements.plus.com>

These are the first lines of r.example main.c (that I renamed in main.cc)

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

extern “C”
{
#include <grass/gis.h>
#include <grass/glocale.h>
}

extern CELL f_c(CELL);
extern FCELL f_f(FCELL);
extern DCELL f_d(DCELL);

And this is its makefile I edit as you told me to do:

MODULE_TOPDIR = …/…
PGM = r.example

LIBES = $(GISLIB)
DEPENDENCIES = $(GISDEP)

MOD_OBJS := $(subst .cc,.o,$(wildcard *.cc))

include $(MODULE_TOPDIR)/include/Make/Module.make

default: cmd

Then I typed make and here the message:

make: *** No rule to make target OBJ.i686-pc-linux-gnu/main.o', needed by /home/roberto/grass/grass-6.2.3/dist.i686-pc-linux-gnu/bin/r.example’. Stop.
roberto@roberto-laptop:~/grass/grass-6.2.3/raster/r.example$

Glynn Clements glynn@gclements.plus.com ha scritto:

roberto caselli wrote:

Thank you very much! How can I edit the raster example to have a c++ source code (.cc extension)?
I should edit something in the makefile, but I don’t how to do. Someone could help me?

Add the following line before including the *.make files (e.g. Module.make):

MOD_OBJS := $(subst .cc,.o,$(wildcard *.cc))

By default, MOD_OBJS is determined based upon the .c files in the
directory.

Rules.make already includes pattern rules for compiling .cc and .cpp
files.

Note that the GRASS headers don’t make allowances for use in C++ code,
so you need to use e.g.:

extern “C” {
#include


Scopri il Blog di Yahoo! Mail: trucchi, novità, consigli… e la tua opinione!

roberto caselli wrote:

Then I typed make and here the message:

make: *** No rule to make target `OBJ.i686-pc-linux-gnu/main.o', needed by `/home/roberto/grass/grass-6.2.3/dist.i686-pc-linux-gnu/bin/r.example'. Stop.
roberto@roberto-laptop:~/grass/grass-6.2.3/raster/r.example$

6.2.x doesn't have the pattern rules for C++.

I suggest using 6.3.x; otherwise, you'll need to figure out many of
the C++ issues yourself (raster/r.terraflow/Makefile will provide some
clues).

In general, new code should normally be written against the
development version (i.e. the Subversion trunk).

[However, once 6.3.0 is released, there will be two distinct
development branches, 6.4.x and 7.x. 7.x will be highly unstable for
quite a while, so the 6.4 branch should be used if you want the module
to be usable in the near future.]

--
Glynn Clements <glynn@gclements.plus.com>

Than you for the suggestion, I’m going to install 6.3.0 version.

Glynn Clements glynn@gclements.plus.com ha scritto:

roberto caselli wrote:

Then I typed make and here the message:

make: *** No rule to make target OBJ.i686-pc-linux-gnu/main.o', needed by /home/roberto/grass/grass-6.2.3/dist.i686-pc-linux-gnu/bin/r.example’. Stop.
roberto@roberto-laptop:~/grass/grass-6.2.3/raster/r.example$

6.2.x doesn’t have the pattern rules for C++.

I suggest using 6.3.x; otherwise, you’ll need to figure out many of
the C++ issues yourself (raster/r.terraflow/Makefile will provide some
clues).

In general, new code should normally be written against the
development version (i.e. the Subversion trunk).

[However, once 6.3.0 is released, there will be two distinct
development branches, 6.4.x and 7.x. 7.x will be highly unstable for
quite a while, so the 6.4 branch should be used if you want the module
to be usable in the near future.]


Glynn Clements


Scopri il Blog di Yahoo! Mail: trucchi, novità, consigli… e la tua opinione!

I installed the 6.3.0 version and I try to compile the r.example module with the changes Clements suggest me to have sources with .cc extensions.

I have this error message, now (I think it depends by the compiler):

gcc -L/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -Wl,–export-dynamic -Wl,-rpath-link,/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -o /home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example OBJ.i686-pc-linux-gnu/main.o -lgrass_gis -lgrass_datetime -lz -lm -lz
OBJ.i686-pc-linux-gnu/main.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0’
collect2: ld returned 1 exit status
make: *** [/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example] Error 1
roberto@roberto-laptop:~/grass/grass-6.3.0RC6/raster/r.example$

I read I should use g++ compiler, but i don’t know what I have to change to use it.

Glynn Clements glynn@gclements.plus.com ha scritto:

roberto caselli wrote:

Then I typed make and here the message:

make: *** No rule to make target OBJ.i686-pc-linux-gnu/main.o', needed by /home/roberto/grass/grass-6.2.3/dist.i686-pc-linux-gnu/bin/r.example’. Stop.
roberto@roberto-laptop:~/grass/grass-6.2.3/raster/r.example$

6.2.x doesn’t have the pattern rules for C++.

I suggest using 6.3.x; otherwise, you’ll need to figure out many of
the C++ issues yourself (raster/r.terraflow/Makefile will provide some
clues).

In general, new code should normally be written against the
development version (i.e. the Subversion trunk).

[However, once 6.3.0 is released, there will be two distinct
development branches, 6.4.x and 7.x. 7.x will be highly unstable for
quite a while, so the 6.4 branch should be used if you want the module
to be usable in the near future.]


Glynn Clements


Scopri il Blog di Yahoo! Mail: trucchi, novità, consigli… e la tua opinione!

On Mar 28, 2008, at 5:14 PM, roberto caselli wrote:

I have this error message, now (I think it depends by the compiler):

gcc -L/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -Wl,--export-dynamic -Wl,-rpath-link,/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -o /home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example OBJ.i686-pc-linux-gnu/main.o -lgrass_gis -lgrass_datetime -lz -lm -lz
OBJ.i686-pc-linux-gnu/main.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example] Error 1
roberto@roberto-laptop:~/grass/grass-6.3.0RC6/raster/r.example$

I read I should use g++ compiler, but i don't know what I have to change to use it.

Yes, if you compile with g++ it will make the error go away.

You can change the compiler with the CC environment variable like:

  export CC=g++

And then run the configure command. Or you can edit your Makefile and change the CC variable from gcc to g++. Or you can copy that command and paste it at the command prompt and change gcc to g++ before you hit the enter key (in the directory of the source you are attempting to compile).

Ciao,

Jeshua Lacock, Owner
<http://OpenOSX.com>
phone: 877.240.1364

roberto caselli wrote:

I installed the 6.3.0 version and I try to compile the r.example module with the changes Clements suggest me to have sources with .cc extensions.

I have this error message, now (I think it depends by the compiler):

gcc -L/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -Wl,--export-dynamic -Wl,-rpath-link,/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/lib -o /home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example OBJ.i686-pc-linux-gnu/main.o -lgrass_gis -lgrass_datetime -lz -lm -lz
OBJ.i686-pc-linux-gnu/main.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [/home/roberto/grass/grass-6.3.0RC6/dist.i686-pc-linux-gnu/bin/r.example] Error 1
roberto@roberto-laptop:~/grass/grass-6.3.0RC6/raster/r.example$

I read I should use g++ compiler, but i don't know what I have to change to use it.

Right; you also need to link with $(CXX) rather than $(CC). Putting:

  CC = $(CXX)

into r.example/Makefile is probably the simplest solution.

--
Glynn Clements <glynn@gclements.plus.com>