[GRASS-dev] Compile r.example for GRASS6.4 in Windows

Greetings all

First of all let me thank Glynn and Markus for helping me on this. This is breaking my head...

1- First I installed GRASS6.4 binaries in C:/grass6

2- I used this website to install msys and libraries in order to compile C functions, just like r.example.
http://trac.osgeo.org/grass/wiki/CompileOnWindows
OSGEO4w was installed in c:/osgeo4w

3- I place r.example folder in code in C:/grass6/tests/r.example

4- So far, so good. Using msys I decided to compile using make file.
After a few try outs, Glynnn told me to use this expression:
make -C c:/grass6/tests/r.example MODULE_TOPDIR=c:/grass6

and I got a few errors. Glynn also told me to change a few variables at c:/grass6/include/make
Those were:
- At platform.make now it's:
GRASS_HOME = /c/grass6
RUN_GISBASE = c:/grass6

- At platform.make I left ARCH empty:

- At grass.make now they are written in msys style:
ARCH_DISTDIR = /c/grass6
ARCH_BINDIR = /c/grass6/bin
ERRORLOG = /c/grass6

5- Then I was getting this error, with a few other small
*** No rule to make target `/c/grass6/lib/libgrass_gis.dll', needed by

6- Markus suggested me to make a copy of libgrass_gis.6.4.0svn.dll with the name libgrass_gis.dll.

7- And after this I got this error:
make: Entering directory `/c/grass6/tests/r.example'
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'
test -d OBJ. || mkdir -p OBJ.
gcc -I/c/grass6/include -I/OSGeo4W/apps/gdal-16/include -I/OSGeo4W/include -g -O2 -I/OSGeo4W/apps/gdal-16/include -I/OSGeo4W/include -DPACKAGE=\""grassmods"\" -I/c/grass6/include -o OBJ./main.o -c main.c
gcc -L/c/grass6/lib -Wl,--export-dynamic,--enable-runtime-pseudo-reloc -L/OSGeo4W/apps/gdal-16/lib -L/OSGeo4W/lib -o /c/grass6/bin/r.example.exe OBJ./main.o c:/grass6/lib/gis/OBJ./fmode.o -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz -lintl -lxdr -liberty -lws2_32 -lz
gcc.exe: c:/grass6/lib/gis/OBJ./fmode.o: No such file or directory
make: *** [/c/grass6/bin/r.example.exe] Error 1
make: Leaving directory `/c/grass6/tests/r.example'

At C:/grass6/tests/r.example a new folder was created "OBJ " with the file main.o.

Question? What else Should I do or what am I doing wrong?
After this; I promise I will submit my quest in GRASS Wiki :slight_smile:

Thanks

Best Regards
Antonio ROcha

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4617 (20091118) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

ERRORLOG = /c/grass6

Note: this needs to refer to a file, not a directory. The default is
$(GRASS_HOME)/error.log.

5- Then I was getting this error, with a few other small
*** No rule to make target `/c/grass6/lib/libgrass_gis.dll', needed by

6- Markus suggested me to make a copy of libgrass_gis.6.4.0svn.dll with
the name libgrass_gis.dll.

Ah. On Unix, the libraries include the version number, and symlinks
are created without the version number. Windows doesn't have symlinks,
so MSys' "ln -s ..." simply copies the file. Presumably the OSGeo4W
installer omits the unversioned files to save space. This will prevent
you from being able to build modules against the libraries, so you
will need to manually make copies without the version number.

We need to come up with a solution for this. Options include:

1. Omitting the version number altogether on Windows.
2. Creating linker scripts[*] on Windows, in place of the symlinks.
3. Creating import libraries on Windows, in place of the symlinks.
4. Including both versioned and unversioned DLLs in the Windows installer.
5. Including the version number in the -l switch.

[*] I don't know whether MinGW actually supports linker scripts.

7- And after this I got this error:

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

Does fmode.o exist anywhere in c:/grass6?

If it does, you can override the location with e.g.:

  make ... FMODE_OBJ=/path/to/fmode.o

If it doesn't, you'll need to create it first. The source file
(fmode.c) is just:

  #include <stdlib.h>
  #include <fcntl.h>
  #undef _fmode
  int _fmode = _O_BINARY;

You can compile it with "gcc -c fmode.c".

In 7.0, the fmode.o file is created as $(GISBASE)/lib/fmode.o, so it
should be included in binary packages.

make: *** [/c/grass6/bin/r.example.exe] Error 1
make: Leaving directory `/c/grass6/tests/r.example'

At C:/grass6/tests/r.example a new folder was created "OBJ " with the
file main.o.

This indicates that the source code compiled but couldn't be linked.

Question? What else Should I do or what am I doing wrong?

You aren't doing anything wrong here. Both of the above problems are a
result of the Windows binary packages for GRASS 6.x being incomplete.

Unfortunately, we don't have any "active" Windows developers.
Occasionally people will build Windows packages or run specific tests
on Windows, but the active developers are all using Linux or MacOSX as
their main platform.

Also, some of the things which cause problems on Windows (e.g. relying
upon shell scripts) can't easily be fixed in 6.x. In 7.0, we are less
worried about compatibility, so it's easier to change things.

In 6.x, building modules against an installed version of GRASS still
isn't ideal even on Unix, and most things are a bit more trouble on
Windows than they are on Unix.

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

Ok here it goes. Another chapter around the compilation of r.example in WINDOWS XP :slight_smile:

After following Glynn suggestion of changing names of Dll files, I tried to run MAKE and I got the following error
The error is
make: Entering directory `/c/grass6/tests/r.example'
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 -L/c/grass6/lib -Wl,--export-dynamic,--enable-runtime-pseudo-reloc -L/c/OSGeo4W/apps/gdal-16/lib -L/c/OSGeo4W/lib -o /c/grass6/bin/r.example.exe OBJ./a/main.o C:/grass6/fmode.o -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz -lxdr -liberty -lws2_32 -lz
c:\osgeo4w\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgrass_datetime
collect2: ld returned 1 exit status
make: *** [/c/grass6/bin/r.example.exe] Error 1
make: Leaving directory `/c/grass6/tests/r.example'

There is no file with that name neigter lxdr neither liberty. The this is at grass.make DATETIME_LIBNAME is defined:
DATETIME_LIBNAME = grass_datetime
and then DATETIMELIB is defined as
DATETIMELIB = -l$(DATETIME_LIBNAME)

so DATETIMELIB is equal to lgrass_datetime and these files doesn't exist. My question is: Was it suppose to have those files in Windows or they have another name?

Thanks..

Best Regards,
Antonio Rocha

António Rocha wrote:

Uoouu this is a BINGO :slight_smile:
Why?
At grass.make I have a variable named DATETIME_LIBNAME defined like this:
DATETIME_LIBNAME = grass_datetime

And then: DATETIMELIB with this sintax:
DATETIMELIB = -l$(DATETIME_LIBNAME)

this means that he is searching for lgrass_datetime that doesn't exist. and same will happen with the others libs defined in GRASS.make

Question: Can I change the file names to libgrass_XXX. dll (add lib instead of l and add .dll at the end?)

Or I really should have those files?

Best regards,
Antonio Rocha

António Rocha wrote:

The error is
make: Entering directory `/c/grass6/tests/r.example'
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 -L/c/grass6/lib -Wl,--export-dynamic,--enable-runtime-pseudo-reloc -L/c/OSGeo4W/apps/gdal-16/lib -L/c/OSGeo4W/lib -o /c/grass6/bin/r.example.exe OBJ./a/main.o C:/grass6/fmode.o -lgrass_gis -lgrass_datetime -lxdr -liberty -lws2_32 -lz -lxdr -liberty -lws2_32 -lz
c:\osgeo4w\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lgrass_datetime
collect2: ld returned 1 exit status
make: *** [/c/grass6/bin/r.example.exe] Error 1
make: Leaving directory `/c/grass6/tests/r.example'

Apply the same solution as for -lgrass_gis, i.e. copy
libgrass_datetime.6.4.svn.dll (or whatever the exact name is) to
libgrass_datetime.dll.

I suggest doing this now for all of the libraries, e.g.:

cd dist./lib
for file in *.svn.dll ; do cp "$file" "${file%.6.*.svn.dll}.dll" ; done

Ok I have done that, but it's still the same error. Because he is not searching for libgrass_datetime.dll but for lgrass_datetime. And there is no file with that name.

I'm writting all of this in order to write a wiki about compiling r.example or a module in WINDOWS :slight_smile:

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4622 (20091119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4622 (20091119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4622 (20091119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4622 (20091119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4622 (20091119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha wrote:

cannot find -lgrass_datetime

There is no file with that name neigter lxdr neither liberty. The this
is at grass.make DATETIME_LIBNAME is defined:
DATETIME_LIBNAME = grass_datetime
and then DATETIMELIB is defined as
DATETIMELIB = -l$(DATETIME_LIBNAME)

so DATETIMELIB is equal to lgrass_datetime

No, it's equal to -lgrass_datetime (note the leading dash); -l is a
switch; the linker adds the "lib" prefix itself.

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