[GRASS-dev] G7: landsat_met.c:103: undefined reference to `chrncpy'

Glynn Clements glynn at gclements.plus.com
Tue Jul 30 10:10:43 PDT 2013


Markus Neteler wrote:

> > I think it needs additional LDFLAGS too.
> 
> I tried to no avail.
> 
> But MarkusM spotted this change which helps:
> 
> Index: landsat_met.c
> ===================================================================
> --- landsat_met.c	(revision 57320)
> +++ landsat_met.c	(working copy)
> @@ -17,7 +17,7 @@
>  #define TM5_MET_SIZE    28700	/* .met file size 28686 bytes */
> 
> 
> -inline void chrncpy(char *dest, char src[], int n)
> +static void chrncpy(char *dest, char src[], int n)
>  {
>      int i;
> 
> I will submit that if no objections.

The question is, why does it only happen for this file?

Searching for "\<inline\>" in *.c gives:

raster/r.statistics3/main.c:54:static inline int get_slot(DCELL c)
raster/r.statistics3/main.c:65:static inline double get_quantile(struct basecat *bc, int n)
raster/r.quantile/main.c:42:static inline int get_slot(DCELL c)
raster/r.quantile/main.c:53:static inline double get_quantile(int n)
vector/v.mapcalc/list.c:140:inline LIST *listprep(LIST * head, LIST * elt)
vector/v.mapcalc/list.c:290:inline int listcnt(LIST * head)
vector/v.mapcalc/list.c:536:inline void listforeach(LIST * head, actfunc action)
vector/v.mapcalc/list.c:574:inline LIST *listlast(LIST * head)
vector/v.mapcalc/vector.c:72:static inline int _is_zero(double r);
vector/v.mapcalc/vector.c:410:static inline int _is_zero(double r)
vector/v.generalize/point.c:26:inline void point_subtract(POINT a, POINT b, POINT * res)
vector/v.generalize/point.c:34:inline void point_add(POINT a, POINT b, POINT * res)
vector/v.generalize/point.c:47:inline double point_dist2(POINT a)
vector/v.generalize/point.c:52:inline void point_assign(struct line_pnts *Points, int index, int with_z,
vector/v.generalize/point.c:70:inline void point_scalar(POINT a, double k, POINT * res)
vector/v.generalize/point.c:78:inline void points_copy_last(struct line_pnts *Points, int pos)
vector/v.generalize/point.c:89:inline double point_dist(POINT a, POINT b)
vector/v.generalize/point.c:95:inline double point_dist_square(POINT a, POINT b)
vector/v.generalize/point.c:101:inline double point_angle_between(POINT a, POINT b, POINT c)
vector/v.generalize/point.c:108:inline double point_dist_segment_square(POINT a, POINT b, POINT c, int with_z)
imagery/i.landsat.toar/landsat_met.c:20:inline void chrncpy(char *dest, char src[], int n)

So I would expect to see issues with vector/v.mapcalc/list.c and
vector/v.generalize/point.c. However, I note that both of those files
include headers with "extern" declarations for the functions in
question, while landsat_met.c doesn't, so I suspect that is the issue
here.

FWIW, I'd suggest that any functions which actually warrant an
"inline" qualifier (which doesn't include chrncpy()) should actually
be "static inline".

In general, functions should only be declared as "inline" if:
a) they are particularly simple (e.g. no loops), and
b) they are called many times (e.g. once per cell).

Also, there's no point in declaring a function "inline" unless it's
either defined in a header (in which case it must be "static inline")
or used in the same file in which it's defined (thus most of the
functions in v.generalize/point.c shouldn't be "inline").

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


More information about the grass-dev mailing list