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

Fails to build on FreeBSD: error: implicit declaration of function ‘TAILQ_END’ (with -Werror) #168

Closed
bombadil opened this issue Sep 22, 2021 · 6 comments

Comments

@bombadil
Copy link
Collaborator

I tried to compile smcroute on Debian's FreeBSD architecture, but it failed:

make[2]: Entering directory '/home/micha/smcroute-master/src'
gcc -DHAVE_CONFIG_H -I. -I..  -D_ATFILE_SOURCE -D_INCOMPLETE_XOPEN_C063 -DSYSCONFDIR=\"/etc\" -DRUNSTATEDIR=\"/run\" -Wdate-time -D_FORTIFY_SOURCE=2 -W -Wall -Wextra -Wno-deprecated-declarations -std=gnu99  -g -O2 -ffile-prefix-map=/home/micha/smcroute-master=. -fstack-protector-strong -Wformat -Werror=format-security -Werror -ggdb -c -o smcrouted-iface.o `test -f 'iface.c' || echo './'`iface.c
iface.c: In function ‘iface_match_by_name’:
iface.c:294:25: error: implicit declaration of function ‘TAILQ_END’; did you mean ‘TAILQ_HEAD’? [-Werror=implicit-function-declaration]
  294 |  while (state->iface != TAILQ_END(&iface_list)) {
      |                         ^~~~~~~~~
      |                         TAILQ_HEAD
iface.c:294:22: error: comparison between pointer and integer [-Werror]
  294 |  while (state->iface != TAILQ_END(&iface_list)) {
      |                      ^~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:539: smcrouted-iface.o] Error 1

I'll continue to poke around tomorrow, but I wanted to share at least this finding already...

@bombadil bombadil changed the title Fails to build on FreeBSD (with -Werror) Fails to build on FreeBSD: error: implicit declaration of function ‘TAILQ_END’ (with -Werror) Sep 22, 2021
@troglobit
Copy link
Owner

Interesting! I've made it a habit of always building and testing on FreeBSD before release, but I've not seen anything like that before. I just double checked, and even latest master builds fine; no warnings (we have -W -Wall -Wextra enabled by default).

The local copy of queue.h (which includes the _SAFE macros) is always used, but it's included last in all .c files that require it. And since it's the the same #ifndef guard as the official one, I guess one of the system headers may have pulled in the sys/queue.h version on kFreeBSD ... which perhaps doesn't have the TAILQ_HEAD/_END macros? I couldn't find any installer for Debian GNU/kFreeBSD on my first couple of googlings, but I guess moving/adding an explicit #include "queue.h" early in each .c file that uses the queue macros, instead of after the system headers, would fix this problem.

troglobit added a commit that referenced this issue Sep 23, 2021
Possible root cause for issue #168, trouble building on Debian/kFreeBSD.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
@troglobit
Copy link
Owner

I just pushed a speculative fix, hopefully it solves the issue.

@bombadil
Copy link
Collaborator Author

Yeah, slightly better.
Next build failure:

gcc -DHAVE_CONFIG_H -I. -I..  -D_ATFILE_SOURCE -D_INCOMPLETE_XOPEN_C063 -DSYSCONFDIR=\"/etc\" -DRUNSTATEDIR=\"/run\" -Wdate-time -D_FORTIFY_SOURCE=2 -W -Wall -Wextra -Wno-deprecated-declarations -std=gnu99  -g -O2 -ffile-prefix-map=/home/micha/smcroute-master=. -fstack-protector-strong -Wformat -Werror=format-security -Werror -ggdb -c -o smcrouted-mrdisc.o `test -f 'mrdisc.c' || echo './'`mrdisc.c
mrdisc.c:28:2: error: #error Currently only works on Linux, patches for FreeBSD are most welcome.
   28 | #error Currently only works on Linux, patches for FreeBSD are most welcome.
      |  ^~~~~
mrdisc.c: In function 'inet_open':
mrdisc.c:171:18: error: storage size of 'mreq' isn't known
  171 |  struct ip_mreqn mreq;
      |                  ^~~~
mrdisc.c:182:33: error: 'SO_BINDTODEVICE' undeclared (first use in this function)
  182 |  if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
      |                                 ^~~~~~~~~~~~~~~
mrdisc.c:182:33: note: each undeclared identifier is reported only once for each function it appears in
mrdisc.c:171:18: error: unused variable 'mreq' [-Werror=unused-variable]
  171 |  struct ip_mreqn mreq;
      |                  ^~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:735: smcrouted-mrdisc.o] Error 1
make[2]: Leaving directory '/home/micha/smcroute-master/src'

@bombadil
Copy link
Collaborator Author

Configuring the build with ./configure --disable-mrdisc makes the build succeed.
So, I consider this issue solved. Thanks.

@troglobit
Copy link
Owner

Awesome, great then I can proceed with the patch release :)

Yeah, the mrdisc code doesn't work on a FreeBSD kernel yet. I wanted to add IPv6 support to it first, but haven't had the time to do either.

@troglobit
Copy link
Owner

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

2 participants