[GRASS-dev] undefined reference to G_alloc_matrix()

Hello,

I am trying to keep temporary files in DCELL **G_alloc_matrix(nrows,ncols)

on compilation I get an undefined reference to that function...

Checked in gis.h it is referring to gisdefs.h which has the definition.
I just svn up on trunk with full distclean and full recompile, still same.

my includes in case this helps...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/glocale.h>

Any idea / suggestion, I am a bit lost here...
Thanks
Yann

--
Yann Chemin
International Rice Research Institute
Office: http://www.irri.org/gis
Perso: http://www.freewebs.com/ychemin

Yann Chemin wrote:

I am trying to keep temporary files in DCELL **G_alloc_matrix(nrows,ncols)

on compilation I get an undefined reference to that function...

Checked in gis.h it is referring to gisdefs.h which has the definition.
I just svn up on trunk with full distclean and full recompile, still same.

Contrary to what you would naturally assume from the headers,
G_alloc_matrix() is actually in the gmath library, so you need to add
$(GMATHLIB) to LIBES.

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

Glynn Clements wrote:

> I am trying to keep temporary files in DCELL **G_alloc_matrix(nrows,ncols)
>
> on compilation I get an undefined reference to that function...
>
> Checked in gis.h it is referring to gisdefs.h which has the definition.
> I just svn up on trunk with full distclean and full recompile, still same.

Contrary to what you would naturally assume from the headers,
G_alloc_matrix() is actually in the gmath library, so you need to add
$(GMATHLIB) to LIBES.

I'm wondering whether those functions (matrix/vector alloc/free)
really belong in the gmath library. It can be quite a heavy
dependency, optionally requiring FFTW, BLAS and LAPACK.

The significance of this is that, if a user installs a binary GRASS
package, and they don't have FFTW (or their version of FFTW is
incompatible with the one used to build the gmath library), it won't
just be the handful of programs which need FFTW which fail to work.

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

On Sat, Aug 2, 2008 at 4:03 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Glynn Clements wrote:

> I am trying to keep temporary files in DCELL **G_alloc_matrix(nrows,ncols)
>
> on compilation I get an undefined reference to that function...
>
> Checked in gis.h it is referring to gisdefs.h which has the definition.
> I just svn up on trunk with full distclean and full recompile, still same.

Contrary to what you would naturally assume from the headers,
G_alloc_matrix() is actually in the gmath library, so you need to add
$(GMATHLIB) to LIBES.

I'm wondering whether those functions (matrix/vector alloc/free)
really belong in the gmath library. It can be quite a heavy
dependency, optionally requiring FFTW, BLAS and LAPACK.

The significance of this is that, if a user installs a binary GRASS
package, and they don't have FFTW (or their version of FFTW is
incompatible with the one used to build the gmath library), it won't
just be the handful of programs which need FFTW which fail to work.

In some cleanup activity we moved it to gmath. Later, gmath got enriched
with FFTW support and such.

It should possibly go back to libgis (in GRASS 7).

Markus

Glynn:

> I'm wondering whether those functions (matrix/vector alloc/free)
> really belong in the gmath library. It can be quite a heavy
> dependency, optionally requiring FFTW, BLAS and LAPACK.
>
> The significance of this is that, if a user installs a binary GRASS
> package, and they don't have FFTW (or their version of FFTW is
> incompatible with the one used to build the gmath library), it won't
> just be the handful of programs which need FFTW which fail to work.

Markus:

In some cleanup activity we moved it to gmath. Later, gmath
got enriched with FFTW support and such.

It should possibly go back to libgis (in GRASS 7).

.... or move FFTW stuff etc. into an "advanced_math" library.

Hamish

Hamish wrote:

> > I'm wondering whether those functions (matrix/vector alloc/free)
> > really belong in the gmath library. It can be quite a heavy
> > dependency, optionally requiring FFTW, BLAS and LAPACK.
> >
> > The significance of this is that, if a user installs a binary GRASS
> > package, and they don't have FFTW (or their version of FFTW is
> > incompatible with the one used to build the gmath library), it won't
> > just be the handful of programs which need FFTW which fail to work.

Markus:
> In some cleanup activity we moved it to gmath. Later, gmath
> got enriched with FFTW support and such.
>
> It should possibly go back to libgis (in GRASS 7).

.... or move FFTW stuff etc. into an "advanced_math" library.

As for FFTW specifically, it would probably be better to just abandon
the GRASS wrapper and have the modules call FFTW directly.

The wrapper exists because GRASS originally had its own FFT
implementation, which was replaced with FFTW to eliminate potential
copyright uncertainties with the FFT code.

Changing the existing function to a wrapper around FFTW was the
quickest way to implement this change, but certainly not the most
efficient.

First, the GRASS interface uses separate real and imaginary arrays,
while FFTW uses a single array of complex values (i.e. interleaved
real and imaginary parts).

Second, the built-in FFT was limited to powers of two for the array
size, while FFTW doesn't have this restriction.

Consequently, any code which uses the fft() function first expands the
data to meet the (obsolete) power-of-two requirement, then a copy of
the expanded data is made to match the FFTW format (even though the
data could invariably have been generated in this format to start
with). The end result is wasted memory and CPU cycles.

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

I added the few lines of code of G_alloc_matrix() inside my code,
since otherwise it would indeed require the whole suite of advanced
math libraries
to be able to use it, and in this case I just needed a trusted Grass way to
allocate to images in memory for a small module (gipe/i.eb.h_SEBAL01).

I would go to move those G_alloc_(i)(f)matrix() to libgis somewhere,
as they dont particularly require anything to work.

2008/8/2 Glynn Clements <glynn@gclements.plus.com>:

Glynn Clements wrote:

> I am trying to keep temporary files in DCELL **G_alloc_matrix(nrows,ncols)
>
> on compilation I get an undefined reference to that function...
>
> Checked in gis.h it is referring to gisdefs.h which has the definition.
> I just svn up on trunk with full distclean and full recompile, still same.

Contrary to what you would naturally assume from the headers,
G_alloc_matrix() is actually in the gmath library, so you need to add
$(GMATHLIB) to LIBES.

I'm wondering whether those functions (matrix/vector alloc/free)
really belong in the gmath library. It can be quite a heavy
dependency, optionally requiring FFTW, BLAS and LAPACK.

The significance of this is that, if a user installs a binary GRASS
package, and they don't have FFTW (or their version of FFTW is
incompatible with the one used to build the gmath library), it won't
just be the handful of programs which need FFTW which fail to work.

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

--
Yann Chemin
International Rice Research Institute
Office: http://www.irri.org/gis
Perso: http://www.freewebs.com/ychemin

Yann Chemin wrote:

I added the few lines of code of G_alloc_matrix() inside my code,
since otherwise it would indeed require the whole suite of advanced
math libraries
to be able to use it, and in this case I just needed a trusted Grass way to
allocate to images in memory for a small module (gipe/i.eb.h_SEBAL01).

I would go to move those G_alloc_(i)(f)matrix() to libgis somewhere,
as they dont particularly require anything to work.

Also, libgmath has two distinct representations for matrices and
vectors. The G_alloc_{i,f,}{matrix,vector} functions just return a
pointer or an array of pointers, while G_matrix_init() returns a
mat_struct. The latter is used with the BLAS/LAPACK functions.

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