[GRASSLIST:2185] new module compilation problems

Hi,
I'm trying to transform a program, that calculates forest carbon fluxes,
in a GRASS module. I have rewritten the main code file and modified some
other code files but when I try to compile it I get some errors. I can't
understand how to correct errors because many of them are in lines with
GRASS libraries. I report the compiler error lines and a piece of the
program.

main.c:30: parse error before `{'
main.c:27: parm types given both in parmlist and separately
main.c:154: `argv' undeclared (first use in this function)
main.c:154: (Each undeclared identifier is reported only once
main.c:154: for each function it appears in.)
main.c:157: warning: assignment from incompatible pointer type
main.c:158: dereferencing pointer to incomplete type

#include "gis.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include "bgc_struct.h" /* data structures for bgc() */
#include "pointbgc_func.h" /* function prototypes for point driver */
#include "bgc_constants.h"

#define DEBUG

struct Cell_head window; /*line 27*/

int main(int argc, char *argv)
{

...
  /*initialize access to database and create temporary files*/
  G_gisinit (argv[0]); /*line 154*/

  /*Set description*/
  module = G_define_module(); /*line 157*/
  module->description = /*line 158*/
   "Calculate the amount of C stocked by forest or vegetated zones";

Perhaps I have written a bad Gmakefile I don't know so I report also it.

------------------------------------------------------------------------
PGM =r.biomebgc

OBJ= main.o bgc.o annual_rates.o atm_pres.o baresoil_evap.o canopy_et.o\
     check_balance.o daily_allocation.o daymet.o dayphen.o decomp.o\
     epc_init.o firstday.o growth_resp.o maint_resp.o\
     make_zero_flux_struct.o metarr_init.o mortality.o nleaching.o\
     outflow.o phenology.o photosynthesis.o prcp_route.o
precision_control.o\
     prephenology.o presim_state_init.o radtrans.o smooth.o snowmelt.o\
     soilpsi.o state_update.o summary.o zero_srcsnk.o
  
LIBES= $(SRC)/raster/r.biomebgc/bgclib411.a

$(BIN_CMD)/$(PGM): $(OBJ) $(GISLIB) $(LIBES)
  $(CC) $(LDFLAGS) -o $@ $(OBJ) $(GISLIB) $(MATHLIB) $(XDRLIB) $(LIBES)

main.o: bgc_struct.h pointbgc_func.h bgc_constants.h
bgc.o: bgc_struct.h bgc_func.h bgc_constants.h
annual_rates.o: bgc_struct.h bgc_func.h bgc_constants.h
atm_pres.o: bgc_struct.h bgc_func.h bgc_constants.h
baresoil_evap.o: bgc_struct.h bgc_func.h bgc_constants.h
canopy_et.o: bgc_struct.h bgc_func.h bgc_constants.h
check_balance.o: bgc_struct.h bgc_func.h bgc_constants.h
daily_allocation.o: bgc_struct.h bgc_func.h bgc_constants.h
daymet.o: bgc_struct.h bgc_func.h bgc_constants.h
dayphen.o: bgc_struct.h bgc_func.h bgc_constants.h
decomp.o: bgc_struct.h bgc_func.h bgc_constants.h
firstday.o: bgc_struct.h bgc_func.h bgc_constants.h
growth_resp.o: bgc_struct.h bgc_func.h bgc_constants.h
maint_resp.o: bgc_struct.h bgc_func.h bgc_constants.h
make_zero_flux_struct.o: bgc_struct.h bgc_func.h bgc_constants.h
mortality.o: bgc_struct.h bgc_func.h bgc_constants.h
nleaching.o: bgc_struct.h bgc_func.h bgc_constants.h
outflow.o: bgc_struct.h bgc_func.h bgc_constants.h
phenology.o: bgc_struct.h bgc_func.h bgc_constants.h
photosynthesis.o: bgc_struct.h bgc_func.h bgc_constants.h
prcp_route.o: bgc_struct.h bgc_func.h bgc_constants.h
precision_control.o: bgc_struct.h bgc_func.h bgc_constants.h
prephenology.o: bgc_struct.h bgc_func.h bgc_constants.h
radtrans.o: bgc_struct.h bgc_func.h bgc_constants.h
snowmelt.o: bgc_struct.h bgc_func.h bgc_constants.h
soilpsi.o: bgc_struct.h bgc_func.h bgc_constants.h
state_update.o: bgc_struct.h bgc_func.h bgc_constants.h
summary.o: bgc_struct.h bgc_func.h bgc_constants.h
zero_srcsnk.o: bgc_struct.h bgc_func.h bgc_constants.h
epc_init.o: bgc_struct.h pointbgc_func.h
metarr_init.o: bgc_struct.h bgc_constants.h pointbgc_func.h misc_func.h
presim_state_init.o: bgc_struct.h pointbgc_func.h
smooth.o: misc_func.h

$(GISLIB): #
------------------------------------------------------------------------
---

Can anybody help me?
Thanks
Chiara

P.S.: I've forgotten to tell I'm using GRASS5pre2 on a linux machine with
Red Hat Linux 6.2

============================
Ing. Chiara Sboarina
Centro di Ecologia Alpina
Viote del Monte Bondone
38040 Sardagna (TN)
Italia

chiara.sboarina@katamail.com wrote:

I'm trying to transform a program, that calculates forest carbon fluxes,
in a GRASS module. I have rewritten the main code file and modified some
other code files but when I try to compile it I get some errors. I can't
understand how to correct errors because many of them are in lines with
GRASS libraries. I report the compiler error lines and a piece of the
program.

main.c:30: parse error before `{'
main.c:27: parm types given both in parmlist and separately
main.c:154: `argv' undeclared (first use in this function)
main.c:154: (Each undeclared identifier is reported only once
main.c:154: for each function it appears in.)
main.c:157: warning: assignment from incompatible pointer type
main.c:158: dereferencing pointer to incomplete type

#include "gis.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include <time.h>

I suggest that you include gis.h *after* you have included the system
headers. gis.h may define macros which interfere with the parsing of
the system headers. More on this below.

Also, I suggest that you check the "bgc" headers for anything which
might cause problems. The fact that you get an error right at the
start of your code suggests that there may be an error there, such as
an unterminated brace.

[The following is a general summary of common issues regarding the use
of header files.]

In general, headers should be included in order from most general to
most specific, i.e.:

1. ANSI C headers (stdio.h etc)

2. Non-ANSI OS headers (unistd.h etc)

3. General external libraries (X11, curses, etc)

4. External libraries which are more specific to the project (e.g. for
a GRASS module, this would include external GIS-related libraries).

5. Libraries which are part of the project (gis.h etc for a GRASS
module).

6. Headers which are part of the actual module (e.g. the local_proto.h
used by many GRASS modules).

Because C doesn't have a formal module system or namespaces, you have
to be careful to avoid the situation where one header defines
something which affects the interpretation of a subsequent header
(preprocessor macros are particularly bad, but typedefs can also cause
problems).

As a general rule, the more widely-used a particular header is, the
more care will be taken not to add unnecessary definitions, and the
more likely that other, less widely-used headers will avoid
conflicting definitions.

A concrete example: the geodesic.h file from the PROJ library defines
macros called "a", "S" and "f":

  # define a GEODESIC.A
  ...
  # define S GEODESIC.DIST
  # define f GEODESIC.FLAT

If you were to include geodesic.h before other headers, there is a
good chance that they will fail; e.g. if a subsequent header declared:

  struct foo {
    int a;
  ...

this would get expanded to:

  struct foo {
    int GEODESIC.A;

which is a syntax error.

--
Glynn Clements <glynn.clements@virgin.net>