Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure does not check for STRDUP #1408

Closed
3 of 9 tasks
zerothi opened this issue May 24, 2019 · 25 comments
Closed
3 of 9 tasks

configure does not check for STRDUP #1408

zerothi opened this issue May 24, 2019 · 25 comments

Comments

@zerothi
Copy link

zerothi commented May 24, 2019

configure does not check for HAVE_STRDUP which makes compilation fail.

Environment Information

Feel free to skip this if the issue is related to documentation, a feature request, or general discussion.

  • What platform are you using? (please provide specific distribution/version in summary)
    • Linux
    • Windows
    • OSX
    • Other
    • NA
  • 32 and/or 64 bit?
    • 32-bit
    • 64-bit
  • What build system are you using?
    • autotools (configure)
    • cmake

Summary of Issue

Configure script does not check for STRDUP.

Steps to reproduce the behavior

I used GCC 9.1.0 and compiled with configure (tried both serial and parallel), both fail.
I guess --enable-netcdf-4 is required. But.

In file included from /usr/include/string.h:630,
                 from ../../libdispatch/nctime.c:23:
../../include/ncconfigure.h:29:14: error: expected identifier or '(' before '__extension__'
   29 | extern char* strdup(const char*);
      |              ^~~~~~

It is pretty clear that cmake checks for the strdup command, while configure does not.

@WardF
Copy link
Member

WardF commented May 24, 2019

Thanks, we’ll get this addressed!

@DennisHeimbigner
Copy link
Collaborator

configure.ac has an AC_CHECK_FUNCS for strdup (about line 823),
so I am not sure what is going on here.

@zerothi
Copy link
Author

zerothi commented May 24, 2019

Thanks!

@DennisHeimbigner I can see now that indeed it does (I only grepped for HAVE_STRDUP which obviously didn' find this...).

I have just tested this with 4.6.3 and 4.7.0, it only happens in 4.7.0...

If you need anymore details, let me know!

@DennisHeimbigner
Copy link
Collaborator

The reason that declaration is in ncconfigure.h is because it is needed
when -ansi is specified to the compiler.
But there is something odd in nccconfigure.h.
I see this:

#ifndef HAVE_STRDUP
extern char* strdup(const char*);
#endif

but later on, I see this:

/*Warning: Cygwin with -ansi does not define these functions
  in its headers.*/
#ifndef _WIN32
#if __STDC__ == 1 /*supposed to be same as -ansi flag */
#ifndef strdup
extern char* strdup(const char*);
#endif
 ...

I have no idea what #ifndef strcat does; is it assuming strcat is a macro?

@zerothi
Copy link
Author

zerothi commented May 24, 2019

Agreed, in git blame it seems it entered around december 2018, so it could be the culprit.

The fix is easy for me. I simply added -DHAVE_STRDUP to my CFLAGS and it worked...

@DennisHeimbigner
Copy link
Collaborator

The base problem is that for gcc, if you specify -ansi, then the headers
do not define strdup, but it turns out that the gcc library in fact defines strdup
anyway. This is why all we need to do is add our own extern strdup decl.
Similar for some other functions.

@DennisHeimbigner
Copy link
Collaborator

Well since I probably caused the problem, I might as well try to fix it and
take credit for it :-)

@DennisHeimbigner
Copy link
Collaborator

As a test of my fix, I am attaching a modified copy of netcdf-c/include/ncconfigure.h.
Can you try it and see if it fixes your problem?
ncconfigure.zip

@zerothi
Copy link
Author

zerothi commented May 27, 2019

@DennisHeimbigner sadly I get the same error:

I here show the full line for compilation for your convenience:

libtool: compile:  mpicc -DHAVE_CONFIG_H -I. -I../../libdispatch -I.. -I../../include -I../../oc2 -I/opt/generic/build-tools/1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/gnu/9.1.0/zlib/1.2.11/include -I/opt/generic/numactl/2.0.12/include -I/opt/gnu/9.1.0/libxml2/2.9.9/include -I/opt/gnu/9.1.0/hwloc/2.0.3/include -I/opt/gnu/9.1.0/ucx/1.5.1/include -I/opt/gnu/9.1.0/openmpi/4.0.1/include -I/opt/gnu/9.1.0/szip/2.1.1/include -I/opt/gnu/9.1.0/hdf5/1.10.5/include -I/opt/gnu/9.1.0/pnetcdf/1.11.2/include -m64 -fPIC -O3 -ftree-vectorize -fexpensive-optimizations -funroll-loops -fprefetch-loop-arrays -march=native -L/opt/generic/build-tools/1.0/lib -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/gnu/9.1.0/zlib/1.2.11/lib -L/opt/generic/numactl/2.0.12/lib -L/opt/gnu/9.1.0/libxml2/2.9.9/lib -L/opt/gnu/9.1.0/hwloc/2.0.3/lib -L/opt/gnu/9.1.0/ucx/1.5.1/lib -L/opt/gnu/9.1.0/openmpi/4.0.1/lib -L/opt/gnu/9.1.0/szip/2.1.1/lib -L/opt/gnu/9.1.0/hdf5/1.10.5/lib -L/opt/gnu/9.1.0/pnetcdf/1.11.2/lib -Wl,-rpath=/opt/generic/build-tools/1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/gnu/9.1.0/zlib/1.2.11/lib -Wl,-rpath=/opt/generic/numactl/2.0.12/lib -Wl,-rpath=/opt/gnu/9.1.0/libxml2/2.9.9/lib -Wl,-rpath=/opt/gnu/9.1.0/hwloc/2.0.3/lib -Wl,-rpath=/opt/gnu/9.1.0/ucx/1.5.1/lib -Wl,-rpath=/opt/gnu/9.1.0/openmpi/4.0.1/lib -Wl,-rpath=/opt/gnu/9.1.0/szip/2.1.1/lib -Wl,-rpath=/opt/gnu/9.1.0/hdf5/1.10.5/lib -Wl,-rpath=/opt/gnu/9.1.0/pnetcdf/1.11.2/lib -MT libdispatch_la-nctime.lo -MD -MP -MF .deps/libdispatch_la-nctime.Tpo -c ../../libdispatch/nctime.c  -fPIC -DPIC -o .libs/libdispatch_la-nctime.o
In file included from /usr/include/string.h:630,
                 from ../../libdispatch/nctime.c:23:
../../include/ncconfigure.h:41:14: error: expected identifier or '(' before '__extension__'
   41 | extern char* strdup(const char*);
      |              ^~~~~~

@zerothi
Copy link
Author

zerothi commented May 27, 2019

As an additional information my config.log has this:

configure:16022: checking for strdup
configure:16022: mpicc -o conftest -m64 -fPIC -O3 -ftree-vectorize -fexpensive-optimizations -funroll-loops -fprefetch-loop-arrays -march=native -L/opt/generic/build-tools/1.0/lib -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/gnu/9.1.0/zlib/1.2.11/lib -L/opt/generic/numactl/2.0.12/lib -L/opt/gnu/9.1.0/libxml2/2.9.9/lib -L/opt/gnu/9.1.0/hwloc/2.0.3/lib -L/opt/gnu/9.1.0/ucx/1.5.1/lib -L/opt/gnu/9.1.0/openmpi/4.0.1/lib -L/opt/gnu/9.1.0/szip/2.1.1/lib -L/opt/gnu/9.1.0/hdf5/1.10.5/lib -L/opt/gnu/9.1.0/pnetcdf/1.11.2/lib -Wl,-rpath=/opt/generic/build-tools/1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/gnu/9.1.0/zlib/1.2.11/lib -Wl,-rpath=/opt/generic/numactl/2.0.12/lib -Wl,-rpath=/opt/gnu/9.1.0/libxml2/2.9.9/lib -Wl,-rpath=/opt/gnu/9.1.0/hwloc/2.0.3/lib -Wl,-rpath=/opt/gnu/9.1.0/ucx/1.5.1/lib -Wl,-rpath=/opt/gnu/9.1.0/openmpi/4.0.1/lib -Wl,-rpath=/opt/gnu/9.1.0/szip/2.1.1/lib -Wl,-rpath=/opt/gnu/9.1.0/hdf5/1.10.5/lib -Wl,-rpath=/opt/gnu/9.1.0/pnetcdf/1.11.2/lib  -I/opt/generic/build-tools/1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/gnu/9.1.0/zlib/1.2.11/include -I/opt/generic/numactl/2.0.12/include -I/opt/gnu/9.1.0/libxml2/2.9.9/include -I/opt/gnu/9.1.0/hwloc/2.0.3/include -I/opt/gnu/9.1.0/ucx/1.5.1/include -I/opt/gnu/9.1.0/openmpi/4.0.1/include -I/opt/gnu/9.1.0/szip/2.1.1/include -I/opt/gnu/9.1.0/hdf5/1.10.5/include -I/opt/gnu/9.1.0/pnetcdf/1.11.2/include  -L/opt/generic/build-tools/1.0/lib -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/gnu/9.1.0/zlib/1.2.11/lib -L/opt/generic/numactl/2.0.12/lib -L/opt/gnu/9.1.0/libxml2/2.9.9/lib -L/opt/gnu/9.1.0/hwloc/2.0.3/lib -L/opt/gnu/9.1.0/ucx/1.5.1/lib -L/opt/gnu/9.1.0/openmpi/4.0.1/lib -L/opt/gnu/9.1.0/szip/2.1.1/lib -L/opt/gnu/9.1.0/hdf5/1.10.5/lib -L/opt/gnu/9.1.0/pnetcdf/1.11.2/lib -Wl,-rpath=/opt/generic/build-tools/1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/gnu/9.1.0/zlib/1.2.11/lib -Wl,-rpath=/opt/generic/numactl/2.0.12/lib -Wl,-rpath=/opt/gnu/9.1.0/libxml2/2.9.9/lib -Wl,-rpath=/opt/gnu/9.1.0/hwloc/2.0.3/lib -Wl,-rpath=/opt/gnu/9.1.0/ucx/1.5.1/lib -Wl,-rpath=/opt/gnu/9.1.0/openmpi/4.0.1/lib -Wl,-rpath=/opt/gnu/9.1.0/szip/2.1.1/lib -Wl,-rpath=/opt/gnu/9.1.0/hdf5/1.10.5/lib -Wl,-rpath=/opt/gnu/9.1.0/pnetcdf/1.11.2/lib conftest.c -lcurl  >&5
conftest.c:87:6: warning: conflicting types for built-in function 'strdup'; expected 'char *(const char *)' [-Wbuiltin-declaration-mismatch]
   87 | char strdup ();
      |      ^~~~~~

which seams to suggest some kind of mismatch?

@DennisHeimbigner
Copy link
Collaborator

That is very odd. This decl "char strdup ();" cannot possibly
be right; strdup returns char*.
I notice you are using mpi. Can you try rebuilding with parallelism turned off?
I am wondering if there are header files used by mpicc that are causing the problem.

@zerothi
Copy link
Author

zerothi commented May 29, 2019

In serial I get exactly the same error (without your patch):

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../libdispatch -I.. -I../../include -I../../oc2 -I/opt/generic/build-tools/1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/gnu/9.1.0/zlib/1.2.11/include -I/opt/gnu/9.1.0/szip/2.1.1/include -I/opt/gnu/9.1.0/hdf5-serial/1.10.5/include -m64 -fPIC -O3 -ftree-vectorize -fexpensive-optimizations -funroll-loops -fprefetch-loop-arrays -march=native -L/opt/generic/build-tools/1.0/lib -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/gnu/9.1.0/zlib/1.2.11/lib -L/opt/gnu/9.1.0/szip/2.1.1/lib -L/opt/gnu/9.1.0/hdf5-serial/1.10.5/lib -Wl,-rpath=/opt/generic/build-tools/1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/gnu/9.1.0/zlib/1.2.11/lib -Wl,-rpath=/opt/gnu/9.1.0/szip/2.1.1/lib -Wl,-rpath=/opt/gnu/9.1.0/hdf5-serial/1.10.5/lib -MT libdispatch_la-nctime.lo -MD -MP -MF .deps/libdispatch_la-nctime.Tpo -c ../../libdispatch/nctime.c  -fPIC -DPIC -o .libs/libdispatch_la-nctime.o
In file included from /usr/include/string.h:630,
                 from ../../libdispatch/nctime.c:23:
../../include/ncconfigure.h:29:14: error: expected identifier or '(' before '__extension__'
   29 | extern char* strdup(const char*);
      |              ^~~~~~
make[2]: *** [Makefile:1049: libdispatch_la-nctime.lo] Error 1
make[2]: Leaving directory '/home/nicpa/installation/bash-build/.compile/netcdf-c-4.7.0/build-tmp/libdispatch'
make[1]: *** [Makefile:700: all-recursive] Error 1
make[1]: Leaving directory '/home/nicpa/installation/bash-build/.compile/netcdf-c-4.7.0/build-tmp'
make: *** [Makefile:545: all] Error 2

@zerothi
Copy link
Author

zerothi commented May 29, 2019

In serial I get exactly the same error (with your patch):

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../libdispatch -I.. -I../../include -I../../oc2 -I/opt/generic/build-tools/1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/generic/gcc/9.1.0/include -I/opt/gnu/9.1.0/zlib/1.2.11/include -I/opt/gnu/9.1.0/szip/2.1.1/include -I/opt/gnu/9.1.0/hdf5-serial/1.10.5/include -m64 -fPIC -O3 -ftree-vectorize -fexpensive-optimizations -funroll-loops -fprefetch-loop-arrays -march=native -L/opt/generic/build-tools/1.0/lib -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/generic/gcc/9.1.0/lib -L/opt/generic/gcc/9.1.0/lib64 -L/opt/gnu/9.1.0/zlib/1.2.11/lib -L/opt/gnu/9.1.0/szip/2.1.1/lib -L/opt/gnu/9.1.0/hdf5-serial/1.10.5/lib -Wl,-rpath=/opt/generic/build-tools/1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/generic/gcc/9.1.0/lib -Wl,-rpath=/opt/generic/gcc/9.1.0/lib64 -Wl,-rpath=/opt/gnu/9.1.0/zlib/1.2.11/lib -Wl,-rpath=/opt/gnu/9.1.0/szip/2.1.1/lib -Wl,-rpath=/opt/gnu/9.1.0/hdf5-serial/1.10.5/lib -MT libdispatch_la-nctime.lo -MD -MP -MF .deps/libdispatch_la-nctime.Tpo -c ../../libdispatch/nctime.c  -fPIC -DPIC -o .libs/libdispatch_la-nctime.o
In file included from /usr/include/string.h:630,
                 from ../../libdispatch/nctime.c:23:
../../include/ncconfigure.h:41:14: error: expected identifier or '(' before '__extension__'
   41 | extern char* strdup(const char*);
      |              ^~~~~~

@DennisHeimbigner
Copy link
Collaborator

DennisHeimbigner commented May 29, 2019

Ok, for the compiler to see that, the two preceding #if tests must be true.
These tests are:

#ifndef _WIN32
#if STDC == 1 /*supposed to be same as -ansi flag */

Since this is linux, the first test is trivially true.
It is the second test that is the problem apparently. My claim that STDC == 1
is same as --ansi must be false, or you are setting STDC or --ansi, which I assume
you are not.
What linus are you running?
Also, is HAVE_STRDUP set in config.h?

@DennisHeimbigner
Copy link
Collaborator

As an experiment, you might try replacing the line:

#if __STDC__ == 1 /*supposed to be same as -ansi flag */
with
#if __STDC_VERSION__ == 199409L /*supposed to be same as -ansi flag */

This comes from looking at this page:
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

@zerothi
Copy link
Author

zerothi commented May 29, 2019

In my config.h I have:

/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1

OS: Linux nicpa-dtu 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux

Custom binutils and latest GCC version.

@DennisHeimbigner
Copy link
Collaborator

Ok, one more test: compile and run this program
and tell me its output.

#include <stdio.h>
#include <stdio.h>
int main()
{
#if __STDC__ == 1
printf("stdc ==1\n");
#else
printf("stdc != 1\n");
#endif
return 0;
}

@zerothi
Copy link
Author

zerothi commented May 29, 2019

I did this:

$> gcc -dM -E - < /dev/null | grep STDC                                                                                                                               
#define __STDC_HOSTED__ 1
#define __STDC_UTF_16__ 1
#define __STDC_IEC_559__ 1
#define __STDC_ISO_10646__ 201605L
#define __STDC_NO_THREADS__ 1
#define _STDC_PREDEF_H 1
#define __STDC_IEC_559_COMPLEX__ 1
#define __STDC_VERSION__ 201710L
#define __GNUC_STDC_INLINE__ 1
#define __STDC_UTF_32__ 1
#define __STDC__ 1

@zerothi
Copy link
Author

zerothi commented May 29, 2019

I'll compile now, and yes it yields: stdc ==1

@DennisHeimbigner
Copy link
Collaborator

ok, I guess that __STDC__==1 is not
the equivalent of -ansi (unless you are for some reason
setting that flag). I any case, it should still work. The errors
you are seeing imply that somehow the symbol "strdup"
is being defined by a macro. I have attached another version
of ncconfigure.h to try.
ncconfigure.zip

@zerothi
Copy link
Author

zerothi commented May 29, 2019

As noted previously it works with 4.6.X using the same procedure.

@zerothi
Copy link
Author

zerothi commented May 29, 2019

That one worked. Everything ran through. :)

@DennisHeimbigner
Copy link
Collaborator

ok, thanks. I must confess I cannot understand why functions like strdup
are being defined as macros, but oh well.

@zerothi
Copy link
Author

zerothi commented May 29, 2019

It is indeed weird...

DennisHeimbigner added a commit that referenced this issue May 29, 2019
re: #1408

1. Add some function tests to configure.ac; these are functions
   not defined with -ansi.
2. When using -ansi, fix include/ncconfigure.h to check for
   the possibilty that certain functions are being defined
   by macros. Apparently Debian does this for some reason.
   No idea why.

Unrelated: modify the debug/cf.cmake debug shell script.
simo-tuomisto added a commit to AaltoSciComp/science-build-rules that referenced this issue Aug 6, 2019
@edwardhartnett
Copy link
Contributor

I believe this issue can be closed.

@WardF WardF closed this as completed Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants