NETWAYS / check_interfaces

Icinga check plugin for network hardware interfaces
GNU General Public License v2.0
11 stars 14 forks source link

[Question]: Is it possible to compile current origin/master on FreeBSD 13.2 #28

Closed mrdsam closed 9 months ago

mrdsam commented 9 months ago

Ask a question

Is it possible to compile current origin/master on FreeBSD 13.2? I get the following error. Any ideas? Version 1.4 works without problems.

  CC       check_interfaces.o
check_interfaces.c: In function 'parse_and_check_commandline':
check_interfaces.c:1262:30: error: array type has incomplete element type 'struct option'
 1262 |         static struct option longopts[] = {
      |                              ^~~~~~~~
check_interfaces.c:1263:29: error: 'no_argument' undeclared (first use in this function)
 1263 |                 {"aliases", no_argument, NULL, 'a'},
      |                             ^~~~~~~~~~~
check_interfaces.c:1263:29: note: each undeclared identifier is reported only once for each function it appears in
check_interfaces.c:1265:31: error: 'required_argument' undeclared (first use in this function)
 1265 |                 {"bandwidth", required_argument, NULL, 'b'},
      |                               ^~~~~~~~~~~~~~~~~
check_interfaces.c:1293:23: warning: implicit declaration of function 'getopt_long' [-Wimplicit-function-declaration]
 1293 |         while ((opt = getopt_long(argc, argv,
      |                       ^~~~~~~~~~~
*** Error code 1

Stop.
RincewindsHat commented 9 months ago

It should be, struct option and friends are part of libc (on my linux at least) and included via "unistd.h"

RincewindsHat commented 9 months ago

ok, I can reproduce this on FreeBSD, but I don't know why (it happens)

mrdsam commented 9 months ago

Hi RincewindsHat, thanks for the hint. I solved it by adding "getopt.h" to check_interfaces.c

index 622bdad..f93637c 100644
--- a/check_interfaces.c
+++ b/check_interfaces.c
@@ -1,3 +1,4 @@
+#include <getopt.h>
 #include "snmp_bulkget.h"
 #include "utils.h"
 #include <net-snmp/net-snmp-config.h>

It has to be at the top of all includes, don't ask me why. Although I'm happy it complies & runs now, I'd like to understand what's going on. Does FreeBSD have a different unistd.h?

I followed this hint, w/o really understanding what I'm doing: https://stackoverflow.com/questions/23382023/error-with-struct-option-array-type-has-incomplete-element-type

RincewindsHat commented 9 months ago

I despaired yesterday after adding it as last ...... Thank you.

mrdsam commented 9 months ago

Thank you very much for the fast fix, works w/o problems now.