[GRASS5] Pre4 on Mac OS X

I have successfully built most of Grass Pre 4 here in Mac OS X land.

I had to edit "configure" for it to configure for postgres: I changed "-lcrypt" to "-lssl -lcrypto" in the "configure" file.

To successfully build "src/libes/proj", I had to edit geod.c: It was pciky about the order of including "ctype.h". Here is the patch:

*** orig/src/libes/proj/geod.c Mon May 27 14:07:06 2002
--- new/src/libes/proj/geod.c Sat Apr 20 12:13:44 2002
***************
*** 4,12 ****
   /* <<<< Geodesic filter program >>>> */
   # include "projects.h"
   # include <stdio.h>
- # include <ctype.h>
   # include "geodesic.h"
   # include "emess.h"
   # include <string.h>

   # define MAXLINE 200
--- 4,12 ----
   /* <<<< Geodesic filter program >>>> */
   # include "projects.h"
   # include <stdio.h>
   # include "geodesic.h"
   # include "emess.h"
+ # include <ctype.h>
   # include <string.h>

   # define MAXLINE 200

__END PATCH

I have run into some linking trouble with geo.point:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o /usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
darwin5.4/libgeo.a -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_ax
_ay
_bx
_by
_use

I thoght it was a link order error, so I tried:

cc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o /usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point LIB.powerpc-apple-darwin5.4/libgeo.a OBJ.powerpc-apple-
darwin5.4/bin_point.o -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_geo_read_control

Any ideas? It seems to be a sort of symbol conflict to me.

Thanks,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

Jeshua Lacock wrote:

I have successfully built most of Grass Pre 4 here in Mac OS X land.

I had to edit "configure" for it to configure for postgres: I changed
"-lcrypt" to "-lssl -lcrypto" in the "configure" file.

OK, I'll add that.

To successfully build "src/libes/proj", I had to edit geod.c: It was
pciky about the order of including "ctype.h".

What exactly was the problem? Error messages?

If a header fails to compile after ctype.h has been included, we may
need to change the header.

I have run into some linking trouble with geo.point:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
darwin5.4/libgeo.a -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_ax
_ay
_bx
_by
_use

These are defined in src/libes/vect32/georef/vars.c, which should be
part of libgeo. Were there any errors in building libgeo?

I thoght it was a link order error, so I tried:

cc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
LIB.powerpc-apple-darwin5.4/libgeo.a OBJ.powerpc-apple-
darwin5.4/bin_point.o -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_geo_read_control

This is defined in src/libes/vect32/georef/geo_file.c, also part of
libgeo. However, I would expect this to generate an error; libraries
must come *after* any files which make use of them.

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

On Monday, May 27, 2002, at 08:10 PM, Glynn Clements wrote:

Jeshua Lacock wrote:

To successfully build "src/libes/proj", I had to edit geod.c: It was
pciky about the order of including "ctype.h".

What exactly was the problem? Error messages?

If a header fails to compile after ctype.h has been included, we may
need to change the header.

Here it is:

gcc -I/usr/src/grass5.0.0pre4/src/include -O2 -no-cpp-precomp -D__unix__ -I. -c geod.c -o OBJ.powerpc-apple-darwin5.4/geod.o
In file included from geod.c:9:
/usr/include/ctype.h:128: parse error before `.'
/usr/include/ctype.h: In function `__istype':
/usr/include/ctype.h:130: `c' undeclared (first use in this function)
/usr/include/ctype.h:130: (Each undeclared identifier is reported only once
/usr/include/ctype.h:130: for each function it appears in.)
/usr/include/ctype.h: At top level:
/usr/include/ctype.h:135: parse error before `.'
/usr/include/ctype.h: In function `__isctype':
/usr/include/ctype.h:137: `c' undeclared (first use in this function)
geod.c: In function `main':
geod.c:133: warning: return type of `main' is not `int'
make: *** [OBJ.powerpc-apple-darwin5.4/geod.o] Error 1

I have actually ran into this quite a few times building various pacakges, and it is just a matter of the order of the includes, or not the right ones included.

I have run into some linking trouble with geo.point:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-
darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
darwin5.4/libgeo.a -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_ax
_ay
_bx
_by
_use

These are defined in src/libes/vect32/georef/vars.c, which should be
part of libgeo. Were there any errors in building libgeo?

Negative, there was no error building libgeo.

Linking in "vars.o" fixed the problem. I realize it is abit of a hack but it seems to work:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o /usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point OBJ.powerpc-apple-darwin5.4/bin_point.o OBJ.powerpc-apple-
darwin5.4/vars.o LIB.powerpc-apple-darwin5.4/libgeo.a -lgis -llock -I/usr -lz

I thoght it was a link order error, so I tried:

cc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
LIB.powerpc-apple-darwin5.4/libgeo.a OBJ.powerpc-apple-
darwin5.4/bin_point.o -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_geo_read_control

This is defined in src/libes/vect32/georef/geo_file.c, also part of
libgeo. However, I would expect this to generate an error; libraries
must come *after* any files which make use of them.

Thanks for the info and all of your help.

I now have successfully built 100% of the modules Pre4, and I am currently uploading the binaries. Markus: I will email you when it is done uploading.

I just read the fix about the "make install" bug, and it installed just fine, and everything seems to work so far.

However, it did complain that I did not set the GISDBASE environment, which I have not needed to set it before. Once I set it everything seems ok.

Also, when I quit Grass, I select the "close all X windows" option, and all the windows and menus close, except for the actual monitors.

Note that I also had to change "<malloc.h>" to "<sys/malloc.h>" for main.c in r.sun and for main.c, dataoct.c, oct.c, user2.c, user4.c in s.vol.rst.

I had to add "-liconv" in src/display/d.text.freetype.

And I had to:

*** orig/dbmscap.c Tue Apr 9 02:09:48 2002
--- new/dbmscap.c Tue May 28 00:43:26 2002
***************
*** 1,3 ****
--- 1,4 ----
+ #include <sys/types.h>
   #include <dirent.h>
   #include <string.h>
   #include <stdlib.h>

Or else I got:

In file included from /usr/include/dirent.h:64,
                  from dbmscap.c:1:
/usr/include/sys/dirent.h:73: parse error before `u_int32_t'
/usr/include/sys/dirent.h:73: warning: no semicolon at end of struct or union
/usr/include/sys/dirent.h:74: warning: data definition has no type or storage class
/usr/include/sys/dirent.h:75: parse error before `d_type'
/usr/include/sys/dirent.h:75: warning: data definition has no type or storage class
/usr/include/sys/dirent.h:76: parse error before `d_namlen'
/usr/include/sys/dirent.h:76: warning: data definition has no type or storage class
/usr/include/sys/dirent.h:83: parse error before `}'
dbmscap.c: In function `db_read_dbmscap':
dbmscap.c:141: invalid use of undefined type `struct dirent'
dbmscap.c:141: dereferencing pointer to incomplete type
dbmscap.c:142: invalid use of undefined type `struct dirent'
dbmscap.c:142: dereferencing pointer to incomplete type
dbmscap.c:144: invalid use of undefined type `struct dirent'
dbmscap.c:144: dereferencing pointer to incomplete type
dbmscap.c:145: invalid use of undefined type `struct dirent'
dbmscap.c:145: dereferencing pointer to incomplete type
make: *** [OBJ.powerpc-apple-darwin5.4/dbmscap.o] Error 1

Cheers,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

Jeshua Lacock wrote:

> > To successfully build "src/libes/proj", I had to edit geod.c: It was
> > pciky about the order of including "ctype.h".
>
> What exactly was the problem? Error messages?
>
> If a header fails to compile after ctype.h has been included, we may
> need to change the header.

Here it is:

gcc -I/usr/src/grass5.0.0pre4/src/include -O2 -no-cpp-precomp
-D__unix__ -I. -c geod.c -o OBJ.powerpc-apple-darwin5.4/geod.o
In file included from geod.c:9:
/usr/include/ctype.h:128: parse error before `.'
/usr/include/ctype.h: In function `__istype':
/usr/include/ctype.h:130: `c' undeclared (first use in this function)
/usr/include/ctype.h:130: (Each undeclared identifier is reported only
once
/usr/include/ctype.h:130: for each function it appears in.)
/usr/include/ctype.h: At top level:
/usr/include/ctype.h:135: parse error before `.'
/usr/include/ctype.h: In function `__isctype':
/usr/include/ctype.h:137: `c' undeclared (first use in this function)

1. Your original patch was reversed. ctype.h currently comes after
geodesic.h and emess.h, and needs to come before.

2. geodesic.h should *definitely* be included last.

The problem is that geodesic.h contains (amongst other things):

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

This is absolutely asking for problems if any headers are included
after geodesic.h.

CC'd to Frank, because this will apply equally to the standalone PROJ
distribution.

geod.c: In function `main':
geod.c:133: warning: return type of `main' is not `int'
make: *** [OBJ.powerpc-apple-darwin5.4/geod.o] Error 1

I have actually ran into this quite a few times building various
pacakges, and it is just a matter of the order of the includes, or not
the right ones included.

In general, headers should be included in the order:

1. Core system headers (stdio.h, ctype.h, ...)
2. Headers for non-core system components (X11, libraries).
3. Headers for core systems of the package being compiled (gis.h, ...)
4. Headers for the specific library/program being compiled (geodesic.h, ...)

Each class of header has an obligation to be compatible with those
above it in the list, but not those below it.

> > I have run into some linking trouble with geo.point:
> >
> > gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-
> > darwin5.4 -o
> > /usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
> > OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
> > darwin5.4/libgeo.a -lgis -llock -I/usr -lz
> > /usr/bin/ld: Undefined symbols:
> > _ax
> > _ay
> > _bx
> > _by
> > _use
>
> These are defined in src/libes/vect32/georef/vars.c, which should be
> part of libgeo. Were there any errors in building libgeo?

Negative, there was no error building libgeo.

Linking in "vars.o" fixed the problem. I realize it is abit of a hack
but it seems to work:

But vars.o *should* be in libgeo.a. Does it appear in the output of
"ar t libgeo.a"? Did you build from a clean tree, or was an older
version of libgeo.a present?

However, it did complain that I did not set the GISDBASE environment,
which I have not needed to set it before. Once I set it everything seems
ok.

What complained?

GISDBASE isn't meant to be an "environment variable", it's a setting
in $GISRC. Although most of the GRASS documentation is totally
confused on this issue, as was some of the code (mostly, code written
in Bourne shell, Tcl or perl; code written in C used G_getenv(), which
got it right).

The startup used to reflect the contents of $GISRC into the
environment; it doesn't any more.

Also, when I quit Grass, I select the "close all X windows" option, and
all the windows and menus close, except for the actual monitors.

Alex reported the cause of this a couple of days ago:

  Subject: [GRASS5] winname.h inconsistency found
  Date: Sun, 26 May 2002 17:27:43 +0400
  Message-ID: <20020526172743.A30504@asrv.fcpf.ru>
  From: Alex Shevlakov <alex@asrv.fcpf.ru>

Note that I also had to change "<malloc.h>" to "<sys/malloc.h>" for
main.c in r.sun and for main.c, dataoct.c, oct.c, user2.c, user4.c in
s.vol.rst.

What functions are those files using? I.e., what functions does the
compiler complain about if you don't include malloc.h?

For malloc(), the correct header to include is stdlib.h, although
certain DOS compiler vendors seemed to think that it belonged in
malloc.h, and a great many DOS programmers seem to have believed the
vendors.

I had to add "-liconv" in src/display/d.text.freetype.

Odd. The configure script should already handle this:

  AC_CHECK_FUNC(iconv, ICONVLIB=, [
  AC_CHECK_LIB(iconv, iconv, ICONVLIB=-liconv, [
  AC_CHECK_LIB(giconv, iconv, ICONVLIB=-lgiconv, [
      AC_MSG_WARN([*** Unable to locate iconv() function.])
      ICONVLIB=
  ])])])
  AC_SUBST(ICONVLIB)

What is the definition of ICONVLIB in your head.<arch> file?

And what are the linker errors if you don't add "-liconv"?

And I had to:

*** orig/dbmscap.c Tue Apr 9 02:09:48 2002
--- new/dbmscap.c Tue May 28 00:43:26 2002
***************
*** 1,3 ****
--- 1,4 ----
+ #include <sys/types.h>
   #include <dirent.h>
   #include <string.h>
   #include <stdlib.h>

OK, I'll fix that.

Except: Radim: isn't dbmscap meant to be dead now?

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

On Tuesday 28 May 2002 11:54 pm, Glynn Clements wrote:

Except: Radim: isn't dbmscap meant to be dead now?

dbmscap file is not used any more, but db_read_dbmscap() in
dbmscap.c yes.

Radim

Radim Blazek wrote:

> Except: Radim: isn't dbmscap meant to be dead now?

dbmscap file is not used any more, but db_read_dbmscap() in
dbmscap.c yes.

So, the rest of dbmscap.c (i.e. everything except db_read_dbmscap()
itself and add_entry()) can be removed?

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

On Wednesday 29 May 2002 10:11 am, Glynn Clements wrote:

Radim Blazek wrote:
> > Except: Radim: isn't dbmscap meant to be dead now?
>
> dbmscap file is not used any more, but db_read_dbmscap() in
> dbmscap.c yes.

So, the rest of dbmscap.c (i.e. everything except db_read_dbmscap()
itself and add_entry()) can be removed?

db_copy_dbmscap_entry () is used by start.c
db_has_dbms() is obviously incorret and not used now, but
I would keep that as:
db_has_dbms(){
    dbDbmscap * dbs;
    dbs = db_read_dbmscap();
    if ( dbs != NULL ) {
        db_free_dbmscap ( dbs);
        return 1;
    } else
        return 0;
}

db_free_dbmscap() is used now here and in start.c also.

Dbmi was already uploaded to grass51 (I have not expected
many changes there, because, there was no activity for years in dbmi)
and in fact, I have removed dbmscap first in grass51 and found as
useful, I have done the same in g50.
So, I would prefer to do this cleanup in grass51 or at least to do the same
cleanup also in grass51.

Radim

On Tuesday, May 28, 2002, at 02:54 PM, Glynn Clements wrote:

Jeshua Lacock wrote:

To successfully build "src/libes/proj", I had to edit geod.c: It was
pciky about the order of including "ctype.h".

What exactly was the problem? Error messages?

If a header fails to compile after ctype.h has been included, we may
need to change the header.

Here it is:

gcc -I/usr/src/grass5.0.0pre4/src/include -O2 -no-cpp-precomp
-D__unix__ -I. -c geod.c -o OBJ.powerpc-apple-darwin5.4/geod.o
In file included from geod.c:9:
/usr/include/ctype.h:128: parse error before `.'
/usr/include/ctype.h: In function `__istype':
/usr/include/ctype.h:130: `c' undeclared (first use in this function)
/usr/include/ctype.h:130: (Each undeclared identifier is reported only
once
/usr/include/ctype.h:130: for each function it appears in.)
/usr/include/ctype.h: At top level:
/usr/include/ctype.h:135: parse error before `.'
/usr/include/ctype.h: In function `__isctype':
/usr/include/ctype.h:137: `c' undeclared (first use in this function)

1. Your original patch was reversed. ctype.h currently comes after
geodesic.h and emess.h, and needs to come before.

Yes I apologize, I realized that after sending the message.

2. geodesic.h should *definitely* be included last.

OK, I just moved string.h to above geodesic.h:

   # include "projects.h"
   # include <ctype.h>
   # include <stdio.h>
   # include <string.h>
   # include "geodesic.h"
   # include "emess.h"

And it builds without a problem. Do you think that is better?

The problem is that geodesic.h contains (amongst other things):

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

This is absolutely asking for problems if any headers are included
after geodesic.h.

CC'd to Frank, because this will apply equally to the standalone PROJ
distribution.

geod.c: In function `main':
geod.c:133: warning: return type of `main' is not `int'
make: *** [OBJ.powerpc-apple-darwin5.4/geod.o] Error 1

I have actually ran into this quite a few times building various
pacakges, and it is just a matter of the order of the includes, or not
the right ones included.

In general, headers should be included in the order:

1. Core system headers (stdio.h, ctype.h, ...)
2. Headers for non-core system components (X11, libraries).
3. Headers for core systems of the package being compiled (gis.h, ...)
4. Headers for the specific library/program being compiled (geodesic.h, ...)

Each class of header has an obligation to be compatible with those
above it in the list, but not those below it.

Thank you very much for the explanation.

I have run into some linking trouble with geo.point:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-
darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
darwin5.4/libgeo.a -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_ax
_ay
_bx
_by
_use

These are defined in src/libes/vect32/georef/vars.c, which should be
part of libgeo. Were there any errors in building libgeo?

Negative, there was no error building libgeo.

Linking in "vars.o" fixed the problem. I realize it is abit of a hack
but it seems to work:

But vars.o *should* be in libgeo.a. Does it appear in the output of
"ar t libgeo.a"? Did you build from a clean tree, or was an older
version of libgeo.a present?

Yes, it is in libgeo.a. I think it may be a linker bug with Darwin or something as much as I can guess.

Yes, it was built from a clean tree.

However, it did complain that I did not set the GISDBASE environment,
which I have not needed to set it before. Once I set it everything seems
ok.

What complained?

d.rast, d.profile, d.vect.area, etc. Any button that lists the DBs vector, raster or site data will display the error, unless I manually set GISDBASE, as far as I tested.

GISDBASE isn't meant to be an "environment variable", it's a setting
in $GISRC. Although most of the GRASS documentation is totally
confused on this issue, as was some of the code (mostly, code written
in Bourne shell, Tcl or perl; code written in C used G_getenv(), which
got it right).

The startup used to reflect the contents of $GISRC into the
environment; it doesn't any more.

Hmm, so do I need to source $GISRC or something whenever the database is set/changed?

Note that I also had to change "<malloc.h>" to "<sys/malloc.h>" for
main.c in r.sun and for main.c, dataoct.c, oct.c, user2.c, user4.c in
s.vol.rst.

What functions are those files using? I.e., what functions does the
compiler complain about if you don't include malloc.h?

Hmm, it just reports about not being able to find malloc:

main.c:46: malloc.h: No Such File or directory.

For malloc(), the correct header to include is stdlib.h, although
certain DOS compiler vendors seemed to think that it belonged in
malloc.h, and a great many DOS programmers seem to have believed the
vendors.

Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So should I remove malloc?

I had to add "-liconv" in src/display/d.text.freetype.

Odd. The configure script should already handle this:

  AC_CHECK_FUNC(iconv, ICONVLIB=, [
  AC_CHECK_LIB(iconv, iconv, ICONVLIB=-liconv, [
  AC_CHECK_LIB(giconv, iconv, ICONVLIB=-lgiconv, [
      AC_MSG_WARN([*** Unable to locate iconv() function.])
      ICONVLIB=
  ])])])
  AC_SUBST(ICONVLIB)

What is the definition of ICONVLIB in your head.<arch> file?

Ah, it is empty.

And what are the linker errors if you don't add "-liconv"?

I get:

/usr/bin/ld: Undefined symbols:

_libiconv
_libiconv_close
_libiconv_open

And I had to:

*** orig/dbmscap.c Tue Apr 9 02:09:48 2002
--- new/dbmscap.c Tue May 28 00:43:26 2002
***************
*** 1,3 ****
--- 1,4 ----
+ #include <sys/types.h>
   #include <dirent.h>
   #include <string.h>
   #include <stdlib.h>

OK, I'll fix that.

Except: Radim: isn't dbmscap meant to be dead now?

Thanks,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

Jeshua Lacock wrote:

> 2. geodesic.h should *definitely* be included last.

OK, I just moved string.h to above geodesic.h:

   # include "projects.h"
   # include <ctype.h>
   # include <stdio.h>
   # include <string.h>
   # include "geodesic.h"
   # include "emess.h"

And it builds without a problem. Do you think that is better?

The fix which I've commited has:

  # include <stdio.h>
  # include <ctype.h>
  # include <string.h>
  # include "projects.h"
  # include "emess.h"
  # include "geodesic.h"

This ordering (ANSI headers first, then the other local headers, with
geodesic.h last) should be the least likely to break if anything is
changed in the future.

>>>> I have run into some linking trouble with geo.point:
>>>>
>>>> gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-
>>>> darwin5.4 -o
>>>> /usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
>>>> OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
>>>> darwin5.4/libgeo.a -lgis -llock -I/usr -lz
>>>> /usr/bin/ld: Undefined symbols:
>>>> _ax
>>>> _ay
>>>> _bx
>>>> _by
>>>> _use
>>>
>>> These are defined in src/libes/vect32/georef/vars.c, which should be
>>> part of libgeo. Were there any errors in building libgeo?
>>
>> Negative, there was no error building libgeo.
>>
>> Linking in "vars.o" fixed the problem. I realize it is abit of a hack
>> but it seems to work:
>
> But vars.o *should* be in libgeo.a. Does it appear in the output of
> "ar t libgeo.a"? Did you build from a clean tree, or was an older
> version of libgeo.a present?

Yes, it is in libgeo.a. I think it may be a linker bug with Darwin or
something as much as I can guess.

Yes, it was built from a clean tree.

Then I would have to suspect a linker bug, or at least some odd
linking semantics which the build mechanism doesn't currently handle.

>> However, it did complain that I did not set the GISDBASE environment,
>> which I have not needed to set it before. Once I set it everything
>> seems
>> ok.
>
> What complained?

d.rast, d.profile, d.vect.area, etc. Any button that lists the DBs
vector, raster or site data will display the error, unless I manually
set GISDBASE, as far as I tested.

Well, the "tcltkgrass" script should have:

  set env(GISDBASE) [exec g.gisenv get=GISDBASE]
  set env(LOCATION_NAME) [exec g.gisenv get=LOCATION_NAME]
  set env(MAPSET) [exec g.gisenv get=MAPSET]

> GISDBASE isn't meant to be an "environment variable", it's a setting
> in $GISRC. Although most of the GRASS documentation is totally
> confused on this issue, as was some of the code (mostly, code written
> in Bourne shell, Tcl or perl; code written in C used G_getenv(), which
> got it right).
>
> The startup used to reflect the contents of $GISRC into the
> environment; it doesn't any more.

Hmm, so do I need to source $GISRC or something whenever the database is
set/changed?

No. The environment variable GISRC should be set (to $HOME/.grassrc5)
at startup. Scripts should call g.gisenv to read settings from that
file. C programs use G_getenv().

>> Note that I also had to change "<malloc.h>" to "<sys/malloc.h>" for
>> main.c in r.sun and for main.c, dataoct.c, oct.c, user2.c, user4.c in
>> s.vol.rst.
>
> What functions are those files using? I.e., what functions does the
> compiler complain about if you don't include malloc.h?

Hmm, it just reports about not being able to find malloc:

main.c:46: malloc.h: No Such File or directory.

No, I mean if you remove the #include statement from main.c.

> For malloc(), the correct header to include is stdlib.h, although
> certain DOS compiler vendors seemed to think that it belonged in
> malloc.h, and a great many DOS programmers seem to have believed the
> vendors.

Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So
should I remove malloc?

Remove the "#include <malloc.h>", and tell me if you get any errors as
a result.

>> I had to add "-liconv" in src/display/d.text.freetype.
>
> Odd. The configure script should already handle this:
>
> AC_CHECK_FUNC(iconv, ICONVLIB=, [
> AC_CHECK_LIB(iconv, iconv, ICONVLIB=-liconv, [
> AC_CHECK_LIB(giconv, iconv, ICONVLIB=-lgiconv, [
> AC_MSG_WARN([*** Unable to locate iconv() function.])
> ICONVLIB=
> ])])])
> AC_SUBST(ICONVLIB)
>
> What is the definition of ICONVLIB in your head.<arch> file?

Ah, it is empty.

> And what are the linker errors if you don't add "-liconv"?

I get:

/usr/bin/ld: Undefined symbols:

_libiconv
_libiconv_close
_libiconv_open

WTF???

So, the test program which "configure" generates links fine, but the
actual program doesn't. I don't see how I can make this test work for
Darwin without making it fail for everything else.

Well, there is the obvious "special case" approach:

  if [ "$ARCH" = "...darwin..." ] ; then
    ICONVLIB=-liconv
  fi

What is the "architecture" name for Darwin (i.e. the suffix of the
head.<arch> file and the OBJ.<arch> directories)?

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

On Wednesday, May 29, 2002, at 03:32 PM, Glynn Clements wrote:

Jeshua Lacock wrote:

2. geodesic.h should *definitely* be included last.

OK, I just moved string.h to above geodesic.h:

   # include "projects.h"
   # include <ctype.h>
   # include <stdio.h>
   # include <string.h>
   # include "geodesic.h"
   # include "emess.h"

And it builds without a problem. Do you think that is better?

The fix which I've commited has:

  # include <stdio.h>
  # include <ctype.h>
  # include <string.h>
  # include "projects.h"
  # include "emess.h"
  # include "geodesic.h"

This ordering (ANSI headers first, then the other local headers, with
geodesic.h last) should be the least likely to break if anything is
changed in the future.

Coolio, that does trick here.

I have run into some linking trouble with geo.point:

gcc -L/usr/src/grass5.0.0pre4/src/libes/LIB.powerpc-apple-
darwin5.4 -o
/usr/src/grass5.0.0pre4/dist.powerpc-apple-darwin5.4/etc/geo.point
OBJ.powerpc-apple-darwin5.4/bin_point.o LIB.powerpc-apple-
darwin5.4/libgeo.a -lgis -llock -I/usr -lz
/usr/bin/ld: Undefined symbols:
_ax
_ay
_bx
_by
_use

These are defined in src/libes/vect32/georef/vars.c, which should be
part of libgeo. Were there any errors in building libgeo?

Negative, there was no error building libgeo.

Linking in "vars.o" fixed the problem. I realize it is abit of a hack
but it seems to work:

But vars.o *should* be in libgeo.a. Does it appear in the output of
"ar t libgeo.a"? Did you build from a clean tree, or was an older
version of libgeo.a present?

Yes, it is in libgeo.a. I think it may be a linker bug with Darwin or
something as much as I can guess.

Yes, it was built from a clean tree.

Then I would have to suspect a linker bug, or at least some odd
linking semantics which the build mechanism doesn't currently handle.

You you think my hack is acceptable? What would be the best thing to test to make sure it works?

However, it did complain that I did not set the GISDBASE environment,
which I have not needed to set it before. Once I set it everything
seems
ok.

What complained?

d.rast, d.profile, d.vect.area, etc. Any button that lists the DBs
vector, raster or site data will display the error, unless I manually
set GISDBASE, as far as I tested.

Well, the "tcltkgrass" script should have:

  set env(GISDBASE) [exec g.gisenv get=GISDBASE]
  set env(LOCATION_NAME) [exec g.gisenv get=LOCATION_NAME]
  set env(MAPSET) [exec g.gisenv get=MAPSET]

GISDBASE isn't meant to be an "environment variable", it's a setting
in $GISRC. Although most of the GRASS documentation is totally
confused on this issue, as was some of the code (mostly, code written
in Bourne shell, Tcl or perl; code written in C used G_getenv(), which
got it right).

The startup used to reflect the contents of $GISRC into the
environment; it doesn't any more.

Hmm, so do I need to source $GISRC or something whenever the database is
set/changed?

No. The environment variable GISRC should be set (to $HOME/.grassrc5)
at startup. Scripts should call g.gisenv to read settings from that
file. C programs use G_getenv().

OK, so it is.

And when I do a 'g.gisenv get=GISDBASE', I get the valid path, so I wonder why I have to set the variable by hand. I am trying to figure it out...

Note that I also had to change "<malloc.h>" to "<sys/malloc.h>" for
main.c in r.sun and for main.c, dataoct.c, oct.c, user2.c, user4.c in
s.vol.rst.

What functions are those files using? I.e., what functions does the
compiler complain about if you don't include malloc.h?

Hmm, it just reports about not being able to find malloc:

main.c:46: malloc.h: No Such File or directory.

No, I mean if you remove the #include statement from main.c.

For malloc(), the correct header to include is stdlib.h, although
certain DOS compiler vendors seemed to think that it belonged in
malloc.h, and a great many DOS programmers seem to have believed the
vendors.

Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So
should I remove malloc?

Remove the "#include <malloc.h>", and tell me if you get any errors as
a result.

For r.sun:main.c I did not get a error by removing malloc.h.

I had to add "-liconv" in src/display/d.text.freetype.

Odd. The configure script should already handle this:

  AC_CHECK_FUNC(iconv, ICONVLIB=, [
  AC_CHECK_LIB(iconv, iconv, ICONVLIB=-liconv, [
  AC_CHECK_LIB(giconv, iconv, ICONVLIB=-lgiconv, [
      AC_MSG_WARN([*** Unable to locate iconv() function.])
      ICONVLIB=
  ])])])
  AC_SUBST(ICONVLIB)

What is the definition of ICONVLIB in your head.<arch> file?

Ah, it is empty.

And what are the linker errors if you don't add "-liconv"?

I get:

/usr/bin/ld: Undefined symbols:

_libiconv
_libiconv_close
_libiconv_open

WTF???

So, the test program which "configure" generates links fine, but the
actual program doesn't. I don't see how I can make this test work for
Darwin without making it fail for everything else.

Well, there is the obvious "special case" approach:

  if [ "$ARCH" = "...darwin..." ] ; then
    ICONVLIB=-liconv
  fi

What is the "architecture" name for Darwin (i.e. the suffix of the
head.<arch> file and the OBJ.<arch> directories)?

powerpc-apple-darwin5.4

Note the 5.4 is subject to change as it is the version:

    hostinfo | grep 'Kernel Version'

% Darwin Kernel Version 5.4:

Jeshua Lacock wrote:

>>>> Linking in "vars.o" fixed the problem. I realize it is abit of a hack
>>>> but it seems to work:
>>>
>>> But vars.o *should* be in libgeo.a. Does it appear in the output of
>>> "ar t libgeo.a"? Did you build from a clean tree, or was an older
>>> version of libgeo.a present?
>>
>> Yes, it is in libgeo.a. I think it may be a linker bug with Darwin or
>> something as much as I can guess.
>>
>> Yes, it was built from a clean tree.
>
> Then I would have to suspect a linker bug, or at least some odd
> linking semantics which the build mechanism doesn't currently handle.

You you think my hack is acceptable? What would be the best thing to
test to make sure it works?

I'd rather try to find out why it fails to link against the vars.o
which is in libgeo.a. Can you send me the appropriate part of the
output from "nm libgeo.a" (the part that refers to vars.o)?

Another odd thing is that there are two other symbols in vars.o,
"residuals" (an array) and "reg_cnt" (an int), but these don't appear
in your error message.

> No. The environment variable GISRC should be set (to $HOME/.grassrc5)
> at startup. Scripts should call g.gisenv to read settings from that
> file. C programs use G_getenv().

OK, so it is.

And when I do a 'g.gisenv get=GISDBASE', I get the valid path, so I
wonder why I have to set the variable by hand. I am trying to figure it
out...

Is this from starting GRASS with the tcltk option (e.g. "grass5 -tcltk",
or just "grass5" if ~/.grassrc5 has "GRASS_GUI: tcltk"), or starting
GRASS with the text interface then running "tcltkgrass" separately?

>> Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So
>> should I remove malloc?
>
> Remove the "#include <malloc.h>", and tell me if you get any errors as
> a result.

For r.sun:main.c I did not get a error by removing malloc.h.

I suspect that the use of malloc.h is just a "DOS programmer" artifact.

>>> And what are the linker errors if you don't add "-liconv"?
>>
>> I get:
>>
>> /usr/bin/ld: Undefined symbols:
>>
>> _libiconv
>> _libiconv_close
>> _libiconv_open
>
> WTF???
>
> So, the test program which "configure" generates links fine, but the
> actual program doesn't. I don't see how I can make this test work for
> Darwin without making it fail for everything else.
>
> Well, there is the obvious "special case" approach:
>
> if [ "$ARCH" = "...darwin..." ] ; then
> ICONVLIB=-liconv
> fi
>
> What is the "architecture" name for Darwin (i.e. the suffix of the
> head.<arch> file and the OBJ.<arch> directories)?

powerpc-apple-darwin5.4

OK, I'll catch this with something like:

  case "$ARCH" in
  powerpc-apple-darwin*)
    ICONVLIB=-liconv ;;
  esac

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

On Wednesday, May 29, 2002, at 10:00 PM, Glynn Clements wrote:

From: Glynn Clements <glynn.clements@virgin.net>
Date: Wed May 29, 2002 10:00:52 PM US/Pacific
To: Jeshua Lacock <jeshua@sierramaps.com>
Cc: GRASS5 <grass5@grass.itc.it>
Subject: Re: [GRASS5] Pre4 on Mac OS X

Jeshua Lacock wrote:

Linking in "vars.o" fixed the problem. I realize it is abit of a hack
but it seems to work:

But vars.o *should* be in libgeo.a. Does it appear in the output of
"ar t libgeo.a"? Did you build from a clean tree, or was an older
version of libgeo.a present?

Yes, it is in libgeo.a. I think it may be a linker bug with Darwin or
something as much as I can guess.

Yes, it was built from a clean tree.

Then I would have to suspect a linker bug, or at least some odd
linking semantics which the build mechanism doesn't currently handle.

You you think my hack is acceptable? What would be the best thing to
test to make sure it works?

I'd rather try to find out why it fails to link against the vars.o
which is in libgeo.a. Can you send me the appropriate part of the
output from "nm libgeo.a" (the part that refers to vars.o)?

Another odd thing is that there are two other symbols in vars.o,
"residuals" (an array) and "reg_cnt" (an int), but these don't appear
in your error message.

Cool. here it is:

% nm -x libgeo.a

/usr/src/grass5.0.0pre4/src/libes/vect32/georef/LIB.powerpc-apple-darwin5.
4/libgeo.a(vars.o):
00000050 01 00 0000 00000001 _ax
00000050 01 00 0000 00000005 _ay
00000050 01 00 0000 00000009 _bx
00000050 01 00 0000 0000000d _by
00000004 01 00 0000 00000011 _reg_cnt
00000050 01 00 0000 0000001f _residuals
00000008 01 00 0000 0000002a _rms
00000028 01 00 0000 0000001a _use

No. The environment variable GISRC should be set (to $HOME/.grassrc5)
at startup. Scripts should call g.gisenv to read settings from that
file. C programs use G_getenv().

OK, so it is.

And when I do a 'g.gisenv get=GISDBASE', I get the valid path, so I
wonder why I have to set the variable by hand. I am trying to figure it
out...

Is this from starting GRASS with the tcltk option (e.g. "grass5 -tcltk",
or just "grass5" if ~/.grassrc5 has "GRASS_GUI: tcltk"), or starting
GRASS with the text interface then running "tcltkgrass" separately?

The 3rd one:

% grass5

GRASS 5.0.0pre4 > tcltkgrass&

Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So
should I remove malloc?

Remove the "#include <malloc.h>", and tell me if you get any errors as
a result.

For r.sun:main.c I did not get a error by removing malloc.h.

I suspect that the use of malloc.h is just a "DOS programmer" artifact.

OK, so I assue it would be best to remove the malloc includes?

And what are the linker errors if you don't add "-liconv"?

I get:

/usr/bin/ld: Undefined symbols:

_libiconv
_libiconv_close
_libiconv_open

WTF???

So, the test program which "configure" generates links fine, but the
actual program doesn't. I don't see how I can make this test work for
Darwin without making it fail for everything else.

Well, there is the obvious "special case" approach:

  if [ "$ARCH" = "...darwin..." ] ; then
    ICONVLIB=-liconv
  fi

What is the "architecture" name for Darwin (i.e. the suffix of the
head.<arch> file and the OBJ.<arch> directories)?

powerpc-apple-darwin5.4

OK, I'll catch this with something like:

  case "$ARCH" in
  powerpc-apple-darwin*)
    ICONVLIB=-liconv ;;
  esac

Looks good to me.

Thanks,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

Jeshua Lacock wrote:

> I'd rather try to find out why it fails to link against the vars.o
> which is in libgeo.a. Can you send me the appropriate part of the
> output from "nm libgeo.a" (the part that refers to vars.o)?
>
> Another odd thing is that there are two other symbols in vars.o,
> "residuals" (an array) and "reg_cnt" (an int), but these don't appear
> in your error message.

Cool. here it is:

% nm -x libgeo.a

/usr/src/grass5.0.0pre4/src/libes/vect32/georef/LIB.powerpc-apple-darwin5.
4/libgeo.a(vars.o):
00000050 01 00 0000 00000001 _ax
00000050 01 00 0000 00000005 _ay
00000050 01 00 0000 00000009 _bx
00000050 01 00 0000 0000000d _by
00000004 01 00 0000 00000011 _reg_cnt
00000050 01 00 0000 0000001f _residuals
00000008 01 00 0000 0000002a _rms
00000028 01 00 0000 0000001a _use

So, the symbols are there, but the linker fails to notice them.

Note that a ".a" file is just an archive (in the same sense as ".tar"
or ".zip"); a static library is just an archive of object files. The
copy of vars.o which is stored in the archive should be identical to
the vars.o file itself (you can confirm this by extracting it and
comparing it to the original vars.o).

The only difference between linking against a ".a" file and linking
against a bunch of ".o" files is that, with an archive, the linker
will only include the object files which are actually used; with a
bunch of object files, the linker will include all of them.

It may be that the Darwin linker only uses symbols which correspond to
functions when deciding which object files are needed, so it doesn't
notice that vars.o is required.

I'll look into moving the variable definitions to one of the other
source files, but I need to figure out which one (if my previous
assumption is correct, storing them in a file whose functions aren't
always used wouldn't solve the problem).

If you know of any mailing lists for Darwin development issues, you
might try asking if anyone else has encountered this problem.

>>> No. The environment variable GISRC should be set (to $HOME/.grassrc5)
>>> at startup. Scripts should call g.gisenv to read settings from that
>>> file. C programs use G_getenv().
>>
>> OK, so it is.
>>
>> And when I do a 'g.gisenv get=GISDBASE', I get the valid path, so I
>> wonder why I have to set the variable by hand. I am trying to figure it
>> out...
>
> Is this from starting GRASS with the tcltk option (e.g. "grass5 -tcltk",
> or just "grass5" if ~/.grassrc5 has "GRASS_GUI: tcltk"), or starting
> GRASS with the text interface then running "tcltkgrass" separately?

The 3rd one:

% grass5

GRASS 5.0.0pre4 > tcltkgrass&

Well, $GISRC should be fully initialised by the time that the shell is
started. env(GISDBASE) is set right at the beginning of the
"tcltkgrass" script, so I can't see how any part of tcltkgrass can
complain about it not being set.

You don't have an old copy of the "tcltkgrass" script in your path, do
you? Can you check that the script which is actually being run
contains those lines?

>>>> Looking at r.sun:main.c, it includes both stdlib.h and malloc.h. So
>>>> should I remove malloc?
>>>
>>> Remove the "#include <malloc.h>", and tell me if you get any errors as
>>> a result.
>>
>> For r.sun:main.c I did not get a error by removing malloc.h.
>
> I suspect that the use of malloc.h is just a "DOS programmer" artifact.

OK, so I assue it would be best to remove the malloc includes?

Yes.

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

On Thursday, May 30, 2002, at 07:07 PM, Glynn Clements wrote:

Jeshua Lacock wrote:

I'd rather try to find out why it fails to link against the vars.o
which is in libgeo.a. Can you send me the appropriate part of the
output from "nm libgeo.a" (the part that refers to vars.o)?

Another odd thing is that there are two other symbols in vars.o,
"residuals" (an array) and "reg_cnt" (an int), but these don't appear
in your error message.

Cool. here it is:

% nm -x libgeo.a

/usr/src/grass5.0.0pre4/src/libes/vect32/georef/LIB.powerpc-apple-darwin5.
4/libgeo.a(vars.o):
00000050 01 00 0000 00000001 _ax
00000050 01 00 0000 00000005 _ay
00000050 01 00 0000 00000009 _bx
00000050 01 00 0000 0000000d _by
00000004 01 00 0000 00000011 _reg_cnt
00000050 01 00 0000 0000001f _residuals
00000008 01 00 0000 0000002a _rms
00000028 01 00 0000 0000001a _use

So, the symbols are there, but the linker fails to notice them.

Note that a ".a" file is just an archive (in the same sense as ".tar"
or ".zip"); a static library is just an archive of object files. The
copy of vars.o which is stored in the archive should be identical to
the vars.o file itself (you can confirm this by extracting it and
comparing it to the original vars.o).

The only difference between linking against a ".a" file and linking
against a bunch of ".o" files is that, with an archive, the linker
will only include the object files which are actually used; with a
bunch of object files, the linker will include all of them.

It may be that the Darwin linker only uses symbols which correspond to
functions when deciding which object files are needed, so it doesn't
notice that vars.o is required.

I'll look into moving the variable definitions to one of the other
source files, but I need to figure out which one (if my previous
assumption is correct, storing them in a file whose functions aren't
always used wouldn't solve the problem).

If you know of any mailing lists for Darwin development issues, you
might try asking if anyone else has encountered this problem.

Thanks for the information. I will probe the issue further with my Apple contacts.

No. The environment variable GISRC should be set (to $HOME/.grassrc5)
at startup. Scripts should call g.gisenv to read settings from that
file. C programs use G_getenv().

OK, so it is.

And when I do a 'g.gisenv get=GISDBASE', I get the valid path, so I
wonder why I have to set the variable by hand. I am trying to figure it
out...

Is this from starting GRASS with the tcltk option (e.g. "grass5 -tcltk",
or just "grass5" if ~/.grassrc5 has "GRASS_GUI: tcltk"), or starting
GRASS with the text interface then running "tcltkgrass" separately?

The 3rd one:

% grass5

GRASS 5.0.0pre4 > tcltkgrass&

Well, $GISRC should be fully initialised by the time that the shell is
started. env(GISDBASE) is set right at the beginning of the
"tcltkgrass" script, so I can't see how any part of tcltkgrass can
complain about it not being set.

You don't have an old copy of the "tcltkgrass" script in your path, do
you? Can you check that the script which is actually being run
contains those lines?

No, but It seems that I needed to start Grass with the -tcltk option, at least once, and, it works fine.

Thanks again,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_