GlobalArrays/ga

implicit declaration of function 'getenv' is invalid in C99

Closed this issue · 0 comments

I see this on Mac M1. The fix is trivial and I will do it later if someone else doesn't get to it first, but I don't yet have the things required to git push on this machine.

Problem

I see the following error or an equivalent one in ga-5.8/global/src/nbutil.c, tools/ga-5.8/gaf2c/gaf2c.c, and ga-5.8/tcgmsg/tcgmsg-mpi/nxtval-armci.c:

../ga-5.8/global/src/nbutil.c:127:11: error: implicit declaration of function 'getenv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  value = getenv("COMEX_MAX_NB_OUTSTANDING");
          ^
../ga-5.8/global/src/nbutil.c:127:9: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
  value = getenv("COMEX_MAX_NB_OUTSTANDING");
        ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../ga-5.8/global/src/nbutil.c:129:26: error: implicit declaration of function 'atoi' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    nb_max_outstanding = atoi(value);
                         ^
../ga-5.8/global/src/nbutil.c:225:65: warning: format specifies type 'int' but the argument has type 'Integer' (aka 'long') [-Wformat]
      printf("p[%d] nga_wait_internal: GA NB handle inactive\n",GAme);
                ~~                                              ^~~~
                %ld

Solution

Add the following to ga-5.8/global/src/nbutil.c, tools/ga-5.8/gaf2c/gaf2c.c, and ga-5.8/tcgmsg/tcgmsg-mpi/nxtval-armci.c:

#if HAVE_STDLIB_H
#   include <stdlib.h>
#endif

Compiler

I am using the GCC DragonEgg Clang compiler:

% gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin