libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
532 stars 304 forks source link

-I misordering bug causes -Werror failure #185

Open dmacks opened 3 years ago

dmacks commented 3 years ago

On OS X 10.13 with a previous version (1.x) of libplist installed:

$ CPPFLAGS="-I/sw/include -Werror" LDFLAGS=-L/sw/lib ./configure --prefix=/sw --disable-static
[...]
$ make V=1
[...]
clang -DHAVE_CONFIG_H -I. -I..   -I/sw/include -Werror -Wall -Wextra -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -Wno-strict-aliasing -fvisibility=hidden -I../include -g -O2 -MT plistutil.o -MD -MP -MF .deps/plistutil.Tpo -c -o plistutil.o plistutil.c
plistutil.c:234:13: error: implicit declaration of function 'plist_is_binary' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if (plist_is_binary(plist_entire, read_size))
            ^
plistutil.c:234:13: note: did you mean 'plist_to_bin'?
/sw/include/plist/plist.h:552:20: note: 'plist_to_bin' declared here
    PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_...
                   ^
plistutil.c:248:17: error: implicit declaration of function 'plist_is_binary' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
            if (plist_is_binary(plist_entire, read_size))
                ^
plistutil.c:260:17: error: implicit declaration of function 'plist_is_binary' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
            if (plist_is_binary(plist_entire, read_size)) {
                ^
3 errors generated.

The problem is that the older plist.h in the systemwide directory is being included rather than the one in the source directory because -I../include is after -I/sw/include. If I get rid of -Werror, I see a weird subsequent flag also:

/bin/sh ../libtool  --tag=CC   --mode=link clang -Wall -Wextra -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -Wno-strict-aliasing -fvisibility=hidden -I../include -g -O2  -L/sw/lib -o plistutil plistutil.o ../src/libplist-2.0.la 

Why is -I going to the linker?

All of this is because tools/Makefile.am (and some other Makefile.am also) are passing local -I via AM_CFLAGS instead of AM_CPPFLAGS. "CFLAGS" is the "C compiler" (.c→.o and linking), whereas "CPPFLAGS" is "the →.o stage" (for both C and C++). It's confusing because

dmacks commented 3 years ago

That's also why I see the following during compiling in the src subdir:

/bin/sh ../libtool  --tag=CC   --mode=compile clang -DHAVE_CONFIG_H -I. -I..  -I../include -I.. -I../libcnary/include -I/sw/include -Wall -Wextra -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -Wno-strict-aliasing -fvisibility=hidden -g -O2 -MT plist.lo -MD -MP -MF .deps/plist.Tpo -c -o plist.lo plist.c
[...]
/bin/sh ../libtool  --tag=CXX   --mode=compile clang++ -DHAVE_CONFIG_H -I. -I..  -I../include -I.. -I../libcnary/include -I/sw/include  -g -O2 -MT Node.lo -MD -MP -MF .deps/Node.Tpo -c -o Node.lo Node.cpp

Notice all the -W flags are used only for C not for C++ because again they are being passed as AM_CFLAGS ("C language") not AM_CPPFLAGS ("CPP stage" all languages).