libpicrin
libpicrin copied to clipboard
Redundant declarations in header file breaking build
Hi there, I'm trying to build libpicrin.a
for use in an embedded project. I'm using -Werror -Wredundant-decls
and unfortunately this means that the combination of picrin.h
and picrin/value.h
don't build.
Here is the diff required to reproduce in libpicrin's source:
diff --git a/Makefile b/Makefile
index 9634630..c562a82 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ LIBPICRIN_HEADERS = \
object.h\
state.h
-CFLAGS += -I./include -Wall -Wextra -g
+CFLAGS += -I./include -Wall -Wextra -g -Werror -Wredundant-decls
mini-picrin: ext/main.o libpicrin.a
$(CC) $(CFLAGS) -o $@ ext/main.o libpicrin.a
and the compiler output:
gcc -I./include -Wall -Wextra -g -Werror -Wredundant-decls -c -o ext/main.o ext/main.c
In file included from ext/main.c:5:0:
./include/picrin.h:86:6: error: redundant redeclaration of 'pic_eq_p' [-Werror=redundant-decls]
bool pic_eq_p(pic_state *, pic_value, pic_value);
^
In file included from ./include/picrin.h:54:0,
from ext/main.c:5:
./include/picrin/value.h:250:1: note: previous definition of 'pic_eq_p' was here
pic_eq_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
^
In file included from ext/main.c:5:0:
./include/picrin.h:87:6: error: redundant redeclaration of 'pic_eqv_p' [-Werror=redundant-decls]
bool pic_eqv_p(pic_state *, pic_value, pic_value);
^
In file included from ./include/picrin.h:54:0,
from ext/main.c:5:
./include/picrin/value.h:256:1: note: previous definition of 'pic_eqv_p' was here
pic_eqv_p(pic_state *PIC_UNUSED(pic), pic_value x, pic_value y)
^
... and so on
Compiler version, just in case it's relevant.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Note that although I'm using the build of libpicrin.a
as an example here, this is a problem in the header files, so it happens when I #include <include/picrin.h>
into my own project.
From looking through things here, I think the problem is because the static inline
function definitions in include/picrin/value.h
are declared after they're included in include/picrin.h
. One solution would be to move these functions into a C file (perhaps a new value.c
file?), so they're not shared between compilation units but I guess they're static inline
for performance reasons so that might not be desirable?
If you have a solution in mind, I'd be happy to submit a pull request.