xsdk-project / xsdk-issues

A repository under which GitHub issues not related to a specific xSDK repo can be filed.
7 stars 0 forks source link

superlu_dist build error with clang1700 #230

Closed balay closed 8 months ago

balay commented 9 months ago

xr_l_c170-xsdk-100-linux-clang1700

https://gitlab.com/xsdk-project/spack-xsdk/-/jobs/5276299108

spack-build-out.txt

liuyangzhuan commented 9 months ago

@xiaoyeli I'm not sure how to resolve this. It's simply that the putenv function used in pdtest.c is not available in for some compilers.

balay commented 9 months ago
[balay@pj01 junk]$ cat putenv.c 
#include <stdlib.h>
int main(void)
{
       putenv("hello");
       return 0;
}
[balay@pj01 junk]$ clang putenv.c 
[balay@pj01 junk]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bcdb23ef757b30b4f257092751a403fb56019cc5, for GNU/Linux 3.2.0, not stripped
[balay@pj01 junk]$ clang -std=c99 putenv.c 
putenv.c:4:8: error: call to undeclared function 'putenv'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    4 |        putenv("hello");
      |        ^
putenv.c:4:8: note: did you mean 'getenv'?
/usr/include/stdlib.h:773:14: note: 'getenv' declared here
  773 | extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
      |              ^
1 error generated.
[balay@pj01 junk]$ 

Looks like the issue is with -std=c99 flag.

This looks a bit ad-hoc - so I'm not sure what builds need this flag here.. (and what builds should exclude this).

        if name == "cflags" and "%pgi" not in self.spec:
            flags.append("-std=c99")
balay commented 9 months ago

Note: similar issue with gcc-13.2.1 [but a warnings instead of error]

[balay@pj01 junk]$ gcc putenv.c 
[balay@pj01 junk]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=4cd77177d8219c232127ff627130bd99ac12059d, for GNU/Linux 3.2.0, not stripped
[balay@pj01 junk]$ gcc -std=c99 putenv.c 
putenv.c: In function ‘main’:
putenv.c:4:8: warning: implicit declaration of function ‘putenv’; did you mean ‘getenv’? [-Wimplicit-function-declaration]
    4 |        putenv("hello");
      |        ^~~~~~
      |        getenv
xiaoyeli commented 9 months ago

Thanks @balay for the diagnosis!

The function pototype of putenv() should be in stdlib.h

but I don't think we need to specify older C standard like -std=c99. Can you try not to use it?

liuyangzhuan commented 9 months ago

@balay Can you try remove these lines https://github.com/spack/spack/blob/8248e180ca1588300bb51beee0b7a1ee303b81ac/var/spack/repos/builtin/packages/superlu-dist/package.py#L137

or change flags.append("-std=c99") to
flags.append("-std=c99 -D_XOPEN_SOURCE")

according to https://stackoverflow.com/questions/16863704/stdlib-h-doesnt-have-declaration-for-putenv

balay commented 9 months ago

Ok pushed the following [to test]

-            flags.append("-std=c99")
+            flags.append("-std=c99 -D_XOPEN_SOURCE")

The appropriate fix can be a direct PR to spack.

xiaoyeli commented 8 months ago

This was resolved, so I am closing it.