[GRASS-dev] Compilation errors under MinGW

Hello,

There are a few errors that popped out when I tried to compile MinGW.
As far as I can see only trunk is faulty. I solved the problem by
updating the problematic files from an older revision. Here is the
summary:

COMPILATION ERRORS //in mingw environment
(revision 34688)

/trunk/lib/gis
    locale.c:33: error: `LC_MESSAGES' undeclared (first use in this function)
    // the problem is in locale.h bundled with mingw
    // probably not GRASS' issue but I'm not sure

    mach_name.c:34:6: #if with no expression
    // the #elif at #34 should be #else

    popen.c:55: error: `popen_pid' undeclared (first use in this function)
    // what's the best way to fix this?

    spawn.c: In function `G_spawn':
    spawn.c:84: warning: passing arg 3 of `_spawnv' from incompatible
pointer type
    spawn.c: In function `do_redirects':
    spawn.c:215: warning: control reaches end of non-void function
    spawn.c: In function `do_spawn':
    spawn.c:232: error: `redirects' undeclared (first use in this function)
    spawn.c:232: error: `num_redirects' undeclared (first use in this function)
    spawn.c:233: error: `bindings' undeclared (first use in this function)
    spawn.c:233: error: `num_bindings' undeclared (first use in this function)
    spawn.c:236: error: `background' undeclared (first use in this function)
    spawn.c:236: error: `args' undeclared (first use in this function)
    spawn.c:237: warning: passing arg 4 of `spawnvpe' from
incompatible pointer type
    spawn.c: In function `G_vspawn_ex':
    spawn.c:631: warning: passing arg 1 of `do_spawn' from
incompatible pointer type
    spawn.c:631: error: too many arguments to function `do_spawn'
    spawn.c: In function `G_spawn_ex':
    spawn.c:655: warning: passing arg 1 of `do_spawn' from
incompatible pointer type
    spawn.c:655: error: too many arguments to function `do_spawn'
    // some more errors...

The fix should be straightforward. I can't commit to trunk so I'm
letting you know for these.

Please elaborate on the first error. I fixed it by adding a line
"#define LC_MESSAGES 6" in locale.h, which pretty lame.

Regards,
Rosen Matev

Rosen Matev wrote:

There are a few errors that popped out when I tried to compile MinGW.
As far as I can see only trunk is faulty. I solved the problem by
updating the problematic files from an older revision. Here is the
summary:

COMPILATION ERRORS //in mingw environment
(revision 34688)

/trunk/lib/gis
    locale.c:33: error: `LC_MESSAGES' undeclared (first use in this function)
    // the problem is in locale.h bundled with mingw
    // probably not GRASS' issue but I'm not sure

Okay. LC_MESSAGES is POSIX, not ANSI C. I'll conditionalise that upon
"#ifdef LC_MESSAGES" and move it into the "#if ... defined(USE_NLS)"
part. It isn't meaningful if you aren't building with NLS enabled.

    mach_name.c:34:6: #if with no expression
    // the #elif at #34 should be #else

Okay.

    popen.c:55: error: `popen_pid' undeclared (first use in this function)
    // what's the best way to fix this?

With:

  G_fatal_error("G_popen() not implemented on Windows")

That code was broken in the first place. Previously, it would compile
but wouldn't work:

1. popen_pid[f] wasn't being set in the MinGW version of G_popen(),
but more significantly ...

2. The MinGW version of G_popen() uses execl(), which effectively
terminates the calling process. It should use _spawnl(_P_NOWAIT).

3. It creates the pipe, but doesn't make the child process use it as
its stdin/stdout. AFAIK, the only way to do this with _spawnl() (or
similar CRT functions) is for the caller to _dup2() its own
stdin/stdout, call _spawnl(), then restore the original descriptor.
See lib/db/dbmi_client/start.c.

    spawn.c: In function `G_spawn':

Ugh; I forgot to do the MinGW cases when I updated this.

The fix should be straightforward. I can't commit to trunk so I'm
letting you know for these.

Can you test r34695?

Please elaborate on the first error. I fixed it by adding a line
"#define LC_MESSAGES 6" in locale.h, which pretty lame.

The setlocale() in MSVCRT doesn't understand LC_MESSAGES, so the call
needs to be disabled there. I don't know how gettext handles this on
Windows.

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