Re: [PATCH 3/3] maint: Avoid -Ignulib on standalone examples

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 04, 2019 at 02:12:20PM -0600, Eric Blake wrote:
Travis shows that clang (but not gcc) fails to build after our
recent gnulib updates, due to:


This is a BSD vs Linux thing, we use Travis to get Mac OS X coverage.
I regulary build with clang and did not hit such error.

 CC       domtop/domtop.o
In file included from dommigrate/dommigrate.c:26:
In file included from ../gnulib/lib/stdlib.h:100:
In file included from ../gnulib/lib/unistd.h:40:
In file included from /usr/include/unistd.h:638:
In file included from ../gnulib/lib/sys/select.h:110:
In file included from ../gnulib/lib/signal.h:67:
../gnulib/lib/pthread.h:74:3: error: "Please include config.h first."
#error "Please include config.h first."


The reason for this change is gnulib commit 6954995d
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=6954995d
which started including unistd.h through stdlib.h for some platforms,
thus requiring us to include config.h.

I did not notice this patch before pushing my "include config.h in
examples" solution:
https://libvirt.org/git/?p=libvirt.git;a=object;h=6954995d

This probably stems from gcc and clang having a subtle difference in
-isystem vs. -I include behaviors on #include_next, where that difference
then results in clang trying to pick up same-named gnulib headers merely
because their directory was in the search path, while gcc did not hit
that problem.


IIUC for both compilers the expected behavior is to include gnulib
headers, otherwise there's no point in having gnulib at all.

But for our examples that are intended to be standalone, we want to
work with the bare-bones libc, without any interference from our
<config.h> or from gnulib.  The easiest way to do that is by using
per-binary CPPFLAGS, and including gnulib headers only for example
binaries that still use <config.h>.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>

---
I don't have a local clang setup, so I'm relying on CI testing to
prove whether this fixes the build failures that Travis reported...
---
examples/Makefile.am | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)


Having standalone examples is a nicer soultion than mine.
However, with my commit reverted, tuning examples/admin/logging.c is
needed to make the build pass on FreeBSD for me:
diff --git a/examples/admin/logging.c b/examples/admin/logging.c
index dc1b23aab5..1e72cdd601 100644
--- a/examples/admin/logging.c
+++ b/examples/admin/logging.c
@@ -1,8 +1,8 @@
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

-#include "config.h"
#include <unistd.h>
#include <libvirt/libvirt-admin.h>
#include <libvirt/virterror.h>

This makes me think that the remaining examples don't really need
gnulib, they just include <config.h> to make compilation pass while
including <unistd.h>.

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux