[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] examples: hello-c: Include config.h if HAVE_CONFIG_H is defi
From: |
Marvin Schmidt |
Subject: |
Re: [PATCH] examples: hello-c: Include config.h if HAVE_CONFIG_H is defined |
Date: |
Fri, 16 Sep 2022 10:30:16 +0200 |
Hi Bruno,
Thanks for your quick response!
On Fri, 16 Sept 2022 at 00:07, Bruno Haible <bruno@clisp.org> wrote:
>
> Marvin Schmidt wrote:
> > Recent compilers are becoming stricter about missing function declarations
> > and
> > the autopoint-3 test failed with clang-15 due to an implicit declaration of
> > `getpid()`:
> >
> > > x86_64-pc-linux-musl-cc -DLOCALEDIR=\"/usr/local/share/locale\"
> > > -DHAVE_CONFIG_H -I. -I. -I. -march=native -O2 -pipe -MT hello.o -MD
> > > -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
> > > hello.c:31:63: error: call to undeclared function 'getpid'; ISO C99 and
> > > later do not support implicit function declarations [-Wimplicit
> > > -function-declaration]
> > > printf (_("This program is running as process number %d."), getpid ());
> > > ^
> > > 1 error generated.
> >
> > The `hello.c` source conditionally includes `<unistd.h>` when
> > `HAVE_UNISTD_H`
> > is defined, but since `config.h` wasn't included the define was not present
> >
> > Include `config.h` when `HAVE_CONFIG_H` is defined to fix this
>
> What you describe is true if the configure.ac file would contain an
> invocation of AC_CONFIG_HEADER or AC_CONFIG_HEADERS.
>
> But in the distributed sample the configure.ac file does not contain
> an AC_CONFIG_HEADER or AC_CONFIG_HEADERS invocation. Therefore no
> config.h is generated; instead, all -D options are part of the compiler
> invocations.
>
You're right, I was looking at this from the `autopoint-3` test which creates
a custom configure.ac, which contains `AC_CONFIG_HEADERS([config.h])`
but lacks a check for the `unistd.h` header.
The configure.ac of the hello-c example on the other hand does have a check
for the `unistd.h` but includes it in `hello.c` only if
`HAVE_UNISTD_H` is defined
So from my understanding `hello.c` should include `<unistd.h>`
unconditionally since
configure.ac assures the header is present with `AC_CHECK_HEADERS([unistd.h])`.
And the `autopoint-3` test should add `AC_CHECK_HEADERS([unistd.h])` to the
configure.ac it creates too.
Do you agree or am I missing something?
> When you start with that example and add an AC_CONFIG_HEADERS([config.h]),
> then yes you need a '#include <config.h>' in each *.c source file.
>
> Bruno
>