[GRASS-dev] Error while compiling i.pr Windows GRASS6.4

Greetings all
I'm trying to compile i.pr in WinGRASS 6.4. I have succeed while compiling i.* , r.* and v.* modules/addons but I'm getting some errors in this one.

I'm using the followin command:
make C:/grass6/tests/i.pr MODULE_TOPDIR=C:/grass6

and I get multiple times the following error while compiling:
:\osgeo4w\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgrass_pr
collect2: ld returned 1 exit status
make[1]: *** [/c/grass6/bin/i.pr.sites_aggregate.exe] Error 1
make[1]: Leaving directory `/c/grass6/tests/i.pr/i.pr_sites_aggregate'
make: Leaving directory `/c/grass6/tests/i.pr'

It seems that he is not finding a lgrass_pr library. I have already searched for some dll named "libgrass_pr" but nothing appeared.

Has anyone have an idea of how to fix this?

Thanks

My i.pr makefile is:
MODULE_TOPDIR = ../..

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

SUBDIRS = \
        PRLIB \
    i.pr_blob \
    i.pr_classify \
    i.pr_features \
    i.pr_features_additional \
    i.pr_features_extract \
    i.pr_features_selection \
    i.pr_model \
    i.pr_statistics \
    i.pr_subsets \
    i.pr_training \
    i.pr_uxb \
    i.pr_sites_aggregate

default: subdirs

clean: cleansubdirs

install: installsubdirs

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4654 (20091202) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

Greetings all
I'm trying to compile i.pr in WinGRASS 6.4. I have succeed while
compiling i.* , r.* and v.* modules/addons but I'm getting some errors
in this one.

I'm using the followin command:
make C:/grass6/tests/i.pr MODULE_TOPDIR=C:/grass6

and I get multiple times the following error while compiling:
:\osgeo4w\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe:
cannot find -lgrass_pr
collect2: ld returned 1 exit status
make[1]: *** [/c/grass6/bin/i.pr.sites_aggregate.exe] Error 1
make[1]: Leaving directory `/c/grass6/tests/i.pr/i.pr_sites_aggregate'
make: Leaving directory `/c/grass6/tests/i.pr'

It seems that he is not finding a lgrass_pr library. I have already
searched for some dll named "libgrass_pr" but nothing appeared.

The source code for the library is in i.pr/PRLIB. If you get an error
building this directory, all of the individual i.pr_* modules will
also fail to build.

Whenever you get build errors, always look for the first error; if you
can solve that, the others will often go away.

When building any non-trivial project, always save the output to a
file (rather than letting it just scroll by in the terminal), e.g.:

  make &> build.log

If you want to watch it as well:

  make 2>&1 | tee build.log
or:
  make &> build.log &
  tail -f build.log

Then, if you need to post error messages, you'll have the important
ones from the beginning (terminals often have limited scrollback), and
the text won't be messed up (as sometimes happens if you copy/paste
from a terminal).

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

Greetings all

Glynn thanks for your comment. It was really helpful.

While compiling I think it's not finding libgrass_pr.dll neither libgrass_pr.6.4.0svn.dll. And I don't have those files.

Am I right? If this is the case, Where Can I find these files?

The beggining of this error is:
make: Entering directory `/c/grass6/tests/i.pr'
c:/grass6/include/Make/Grass.make:418: warning: overriding commands for target `/c/grass6/bin'
c:/grass6/include/Make/Grass.make:409: warning: ignoring old commands for target `/c/grass6/bin'
PRLIB
make[1]: Entering directory `/c/grass6/tests/i.pr/PRLIB'
c:/grass6/include/Make/Grass.make:418: warning: overriding commands for target `/c/grass6/bin'
c:/grass6/include/Make/Grass.make:409: warning: ignoring old commands for target `/c/grass6/bin'
gcc -shared -o /c/grass6/lib/libgrass_pr.6.4.0svn.dll -L/c/grass6/lib -Wl,--export-dynamic,--enable-runtime-pseudo-reloc -L/c/OSGeo4W/apps/gdal-16/lib -L/c/OSGeo4W/lib OBJ./a/blob.o OBJ./a/bootstrap.o OBJ./a/dist.o OBJ./a/eigen.o OBJ./a/entropy.o OBJ./a/features.o OBJ./a/features_selection.o OBJ./a/getline.o OBJ./a/gm.o OBJ./a/integration.o OBJ./a/lu.o OBJ./a/matrix.o OBJ./a/min_quadratic.o OBJ./a/nn.o OBJ./a/open.o OBJ./a/pca.o OBJ./a/percent.o OBJ./a/random.o OBJ./a/read_models.o OBJ./a/soft_margin_boosting.o OBJ./a/sort.o OBJ./a/stats.o OBJ./a/svm.o OBJ./a/test.o OBJ./a/training.o OBJ./a/tree.o OBJ./a/write_matrix.o -lgrass_gmath -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz c:/grass6/lib/gis/OBJ./a/dllmain.o && \
    (cd /c/grass6/lib; ln -f -s libgrass_pr.6.4.0svn.dll /c/grass6/lib/libgrass_pr.dll)
gcc.exe: c:/grass6/lib/gis/OBJ./a/dllmain.o: No such file or directory
make[1]: *** [/c/grass6/lib/libgrass_pr.6.4.0svn.dll] Error 1
make[1]: Leaving directory `/c/grass6/tests/i.pr/PRLIB'

Glynn Clements wrote:

António Rocha wrote:

Greetings all
I'm trying to compile i.pr in WinGRASS 6.4. I have succeed while compiling i.* , r.* and v.* modules/addons but I'm getting some errors in this one.

I'm using the followin command:
make C:/grass6/tests/i.pr MODULE_TOPDIR=C:/grass6

and I get multiple times the following error while compiling:
:\osgeo4w\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgrass_pr
collect2: ld returned 1 exit status
make[1]: *** [/c/grass6/bin/i.pr.sites_aggregate.exe] Error 1
make[1]: Leaving directory `/c/grass6/tests/i.pr/i.pr_sites_aggregate'
make: Leaving directory `/c/grass6/tests/i.pr'

It seems that he is not finding a lgrass_pr library. I have already searched for some dll named "libgrass_pr" but nothing appeared.
    
The source code for the library is in i.pr/PRLIB. If you get an error
building this directory, all of the individual i.pr_* modules will
also fail to build.

Whenever you get build errors, always look for the first error; if you
can solve that, the others will often go away.

When building any non-trivial project, always save the output to a
file (rather than letting it just scroll by in the terminal), e.g.:

  make &> build.log

If you want to watch it as well:

  make 2>&1 | tee build.log
or:
  make &> build.log &
  tail -f build.log

Then, if you need to post error messages, you'll have the important
ones from the beginning (terminals often have limited scrollback), and
the text won't be messed up (as sometimes happens if you copy/paste
from a terminal).

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4659 (20091203) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

Glynn thanks for your comment. It was really helpful.

While compiling I think it's not finding libgrass_pr.dll neither
libgrass_pr.6.4.0svn.dll. And I don't have those files.

Am I right? If this is the case, Where Can I find these files?

The problem is that it's failing to *create* them:

The beggining of this error is:

gcc -shared -o /c/grass6/lib/libgrass_pr.6.4.0svn.dll -L/c/grass6/lib

                               ^^^^^^^^^^^^^^^^^^^^^^^^

If this command succeeded, it would create the file
libgrass_pr.6.4.0svn.dll. It's failing due to:

gcc.exe: c:/grass6/lib/gis/OBJ./a/dllmain.o: No such file or directory

This suggests that OBJDIR is "OBJ./a", which is bogus. On Windows, the
typical value is "OBJ.i686-pc-mingw32".

If you have a dllmain.o file anywhere, you can use e.g.

  make ... DLLMAIN_OBJ=/c/grass6/lib/gis/OBJ.OBJ.i686-pc-mingw32/dllmain.o

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

Hello Glynn
I'm afraid I don't have particularly good news. I don't have any dllmain.o file in my GRASS6 folder or even osgeo4w folder. What I do have is in snapshots folder a dllmain.c.
The /OBJ./a/ usually is where it stores the .o files. Usually it should be storing them at c:/grass6/tests/i.pr/PRLIB/OBJ/a. In there there are a lot of .o files but neither dllmain.o is there.

So my question now it's not how to obtain librgrass_pr but how to obtain this dllmain.o.

About the OBJ./a
maybe it has to do with this (at platform.make):
- ARCH = i686-pc-mingw32
- STLIB_SUFFIX = .a

By the way is it worth downloading and compiling /g.extension in order to install addons/modules?

/Thanks Glynn.
Antonio

Glynn Clements wrote:

António Rocha wrote:

Glynn thanks for your comment. It was really helpful.

While compiling I think it's not finding libgrass_pr.dll neither libgrass_pr.6.4.0svn.dll. And I don't have those files.

Am I right? If this is the case, Where Can I find these files?
    
The problem is that it's failing to *create* them:

The beggining of this error is:
    
gcc -shared -o /c/grass6/lib/libgrass_pr.6.4.0svn.dll -L/c/grass6/lib
    

                               ^^^^^^^^^^^^^^^^^^^^^^^^

If this command succeeded, it would create the file
libgrass_pr.6.4.0svn.dll. It's failing due to:

gcc.exe: c:/grass6/lib/gis/OBJ./a/dllmain.o: No such file or directory
    
This suggests that OBJDIR is "OBJ./a", which is bogus. On Windows, the
typical value is "OBJ.i686-pc-mingw32".

If you have a dllmain.o file anywhere, you can use e.g.

  make ... DLLMAIN_OBJ=/c/grass6/lib/gis/OBJ.OBJ.i686-pc-mingw32/dllmain.o

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4660 (20091204) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

I'm afraid I don't have particularly good news. I don't have any
dllmain.o file in my GRASS6 folder or even osgeo4w folder. What I do
have is in snapshots folder a dllmain.c.
The /OBJ./a/ usually is where it stores the .o files. Usually it should
be storing them at c:/grass6/tests/i.pr/PRLIB/OBJ/a. In there there are
a lot of .o files but neither dllmain.o is there.

So my question now it's not how to obtain librgrass_pr but how to obtain
this dllmain.o.

It's normally built from lib/gis/dllmain.c. If you didn't build GRASS
itself from source, you can compile just that file with:

  gcc -c dllmain.c

(it shouldn't need any other switches), then pass its path via
DLLMAIN_OBJ.

About the OBJ./a
maybe it has to do with this (at platform.make):
- ARCH = i686-pc-mingw32
- STLIB_SUFFIX = .a

Those are correct. Check if OBJDIR has the wrong value in
include/Make/Grass.make. It should be:

  # object dir
  OBJDIR = OBJ.$(ARCH)

By the way is it worth downloading and compiling /g.extension in order
to install addons/modules?

I don't know.

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

Hi Glynn
I think you do magic because I've tried a couple of times without success and, right after I received your email I suceed compiling dllmain.c. :slight_smile:

About OBJDIR, At GRASS.make it's defined as you said:
OBJDIR = OBJ.$(ARCH)
So no problem with this

Now, with compiling i.pr:
I'm getting the following error (see below). it has something to do with drand48. drand48 is a function mentioned in line 42 of bootstrap.c of PRLIB folder.
Does this function ring a bell? I have searched and there is no file with that name in GRASS6 folder neither sourcecode or snapshot.

*make: Entering directory `/c/grass6/tests/i.pr'
c:/grass6/include/Make/Grass.make:418: warning: overriding commands for target `/c/grass6/bin'
c:/grass6/include/Make/Grass.make:409: warning: ignoring old commands for target `/c/grass6/bin'
PRLIB
make[1]: Entering directory `/c/grass6/tests/i.pr/PRLIB'
c:/grass6/include/Make/Grass.make:418: warning: overriding commands for target `/c/grass6/bin'
c:/grass6/include/Make/Grass.make:409: warning: ignoring old commands for target `/c/grass6/bin'
gcc -shared -o /c/grass6/lib/libgrass_pr.6.4.0svn.dll -L/c/grass6/lib -Wl,--export-dynamic,--enable-runtime-pseudo-reloc -L/c/OSGeo4W/apps/gdal-16/lib -L/c/OSGeo4W/lib OBJ./a/blob.o OBJ./a/bootstrap.o OBJ./a/dist.o OBJ./a/eigen.o OBJ./a/entropy.o OBJ./a/features.o OBJ./a/features_selection.o OBJ./a/getline.o OBJ./a/gm.o OBJ./a/integration.o OBJ./a/lu.o OBJ./a/matrix.o OBJ./a/min_quadratic.o OBJ./a/nn.o OBJ./a/open.o OBJ./a/pca.o OBJ./a/percent.o OBJ./a/random.o OBJ./a/read_models.o OBJ./a/soft_margin_boosting.o OBJ./a/sort.o OBJ./a/stats.o OBJ./a/svm.o OBJ./a/test.o OBJ./a/training.o OBJ./a/tree.o OBJ./a/write_matrix.o -lgrass_gmath -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz c:/grass6/lib/gis/OBJ./a/dllmain.o && \
    (cd /c/grass6/lib; ln -f -s libgrass_pr.6.4.0svn.dll /c/grass6/lib/libgrass_pr.dll)
OBJ./a/bootstrap.o: In function `Bootsamples':
c:/grass6/tests/i.pr/PRLIB/bootstrap.c:42: undefined reference to `drand48'
OBJ./a/svm.o: In function `examineExample':
c:/grass6/tests/i.pr/PRLIB/svm.c:335: undefined reference to `drand48'
c:/grass6/tests/i.pr/PRLIB/svm.c:346: undefined reference to `drand48'
OBJ./a/svm.o: In function `estimate_cv_error':
c:/grass6/tests/i.pr/PRLIB/svm.c:865: undefined reference to `drand48'
collect2: ld returned 1 exit status
make[1]: *** [/c/grass6/lib/libgrass_pr.6.4.0svn.dll] Error 1
make[1]: Leaving directory `/c/grass6/tests/i.pr/PRLIB'*

Thanks Glynn for your help

Glynn Clements wrote:

António Rocha wrote:

It's normally built from lib/gis/dllmain.c. If you didn't build GRASS
itself from source, you can compile just that file with:

  gcc -c dllmain.c

(it shouldn't need any other switches), then pass its path via
DLLMAIN_OBJ.

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4661 (20091204) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

Hi Glynn
I think you do magic because I've tried a couple of times without
success and, right after I received your email I suceed compiling
dllmain.c. :slight_smile:

About OBJDIR, At GRASS.make it's defined as you said:
OBJDIR = OBJ.$(ARCH)
So no problem with this

Now, with compiling i.pr:
I'm getting the following error (see below). it has something to do with
drand48. drand48 is a function mentioned in line 42 of bootstrap.c of
PRLIB folder.
Does this function ring a bell? I have searched and there is no file
with that name in GRASS6 folder neither sourcecode or snapshot.

drand48() is a standard function on most Unix systems, but Windows
doesn't have it. If you look in include/config.h, you'll see:

  /* define if drand48() exists */
  /* #undef HAVE_DRAND48 */

It's easy enough to simulate it; the following is adapted from
raster/r.mapcalc/xrand.c:

  #if !defined(HAVE_DRAND48)
  #define drand48() ((double)rand()/((double)RAND_MAX + 1))
  #endif

The above should either be added to the top of i.pr/PRLIB/svm.c (if
that is the only file which needs it), or added to
i.pr/include/global.h (if several files need it).

OTOH, if the algorithm requires a high level of randomness, it might
need something better; Windows' rand() function only returns 15 bits
of data, which may not be enough.

A more accurate solution is:

  #if !defined (HAVE_DRAND48)
  #if defined(HAVE_LONG_LONG_INT)
  static unsigned long long state;
  
  /* see:
   * http://www.opengroup.org/onlinepubs/9699919799/functions/drand48.html
   */
  static unsigned long long next(void) {
    state = (0x5DEECE66DULL * state + 0xB) & 0xFFFFFFFFFFFFULL;
    return state;
  }
  
  double drand48(void) {
    return (double) next() / 0x1000000000000ULL;
  }
  #else
  /* no drand48(), no "long long" type, don't know whether "long"
   * is 64-bit and can't be bothered implementing multi-word
   * arithmetic, so we'll have to live with this crude approximation
   */
  #define drand48() ((double)rand()/((double)RAND_MAX + 1))
  #endif
  #endif

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

Hello Glynn and everyone
You can find as an annex to this email the output of the msys make command.
As far as I can see everrything is FINE :slight_smile: and working.
Just one question: during compilation i got these errors: ERROR: G_getenv(): Variable LOCATION_NAME not set
Is this associated with manual html page that is created with the compilation?

Thanks Glynn, you were really helpful
Best Regards,
Antonio Rocha

Glynn Clements wrote:

drand48() is a standard function on most Unix systems, but Windows
doesn't have it. If you look in include/config.h, you'll see:

  /* define if drand48() exists */
  /* #undef HAVE_DRAND48 */

It's easy enough to simulate it; the following is adapted from
raster/r.mapcalc/xrand.c:

  #if !defined(HAVE_DRAND48)
  #define drand48() ((double)rand()/((double)RAND_MAX + 1))
  #endif

The above should either be added to the top of i.pr/PRLIB/svm.c (if
that is the only file which needs it), or added to
i.pr/include/global.h (if several files need it).

OTOH, if the algorithm requires a high level of randomness, it might
need something better; Windows' rand() function only returns 15 bits
of data, which may not be enough.

A more accurate solution is:

  #if !defined (HAVE_DRAND48)
  #if defined(HAVE_LONG_LONG_INT)
  static unsigned long long state;
  
  /* see:
   * http://www.opengroup.org/onlinepubs/9699919799/functions/drand48.html
   */
  static unsigned long long next(void) {
    state = (0x5DEECE66DULL * state + 0xB) & 0xFFFFFFFFFFFFULL;
    return state;
  }
  
  double drand48(void) {
    return (double) next() / 0x1000000000000ULL;
  }
  #else
  /* no drand48(), no "long long" type, don't know whether "long"
   * is 64-bit and can't be bothered implementing multi-word
   * arithmetic, so we'll have to live with this crude approximation
   */
  #define drand48() ((double)rand()/((double)RAND_MAX + 1))
  #endif

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4666 (20091207) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

(attachments)

build.log (51.5 KB)

António Rocha wrote:

Just one question: during compilation i got these errors: ERROR:
G_getenv(): Variable LOCATION_NAME not set
Is this associated with manual html page that is created with the
compilation?

Yes.

The process for generating HTML pages involves running the module with
the --html-description flag. Running any GRASS module requires a
minimal GRASS "session" to be established, which essentially means
that $GISRC must point to a file containing settings for the GISDBASE,
LOCATION_NAME and MAPSET variables

In the case where the module is being run with the --html-description
flag (or --help, etc), the actual value don't matter, but the
variables must be set.

Running make with e.g.:

  GISRC=$HOME/.grassrc6 make ...

should suffice.

In GRASS 7.0, the demolocation directory (which is used to provide a
minimal GRASS session for the normal build process) is installed, so
the rules to build HTML files should work even when building add-on
modules, but this isn't the case for 6.x.

[Actually, most of the problems relating to building add-ons should be
fixed in 7.0, but the existing add-ons are written for 6.x.]

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