0

Does using the POSIX header file #include <net/if.h> require a library to be linked aswell? I get the below error when I use a constant from the header file.

error: IFNAMSIZ undeclared

#include <net/if.h>

int main(int argc, char** argv) {
    char f[IFNAMSIZ]; // compiler error
    return 0;
}

If I need a library, whats the name of it? Something like gcc -o test test.c -lif --std=c11 is not a valid library. Googling this is turning up nothing which is quite frustrating.

*PS: how do you find out what libraries a POSIX header requires?

Solution: The problem is because I am compiling with --std=c11. This question describes the problem and the solution: Why does C99 complain about storage sizes?

Community
  • 1
  • 1
sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

2

From a quick google, it seems the name defined is IF_NAMESIZE, not IFNAMSIZ.

The error you are getting is not from a missing library*, but from a missing definition at the compiler step, which means that the header file does not define IFNAMSIZ.

*) If it were a library issue, you'd see linker errors with 'missing external symbol' messages.

MicroVirus
  • 5,324
  • 2
  • 28
  • 53
  • my header file found by doing `locate net/if.h` defines it as `IFNAMSIZ` and using `IFNAMESIZE` results in the same compiler error – sazr Jun 11 '16 at 10:08
  • There might be more than one `if.h` header on your system. It doesn't seem like the one that gets included defines `IFNAMSIZ`, because else you wouldn't be getting the error message that you are. In particular, the error you are getting is not from a missing library but from a missing definition at the compilation step. – MicroVirus Jun 11 '16 at 10:09
  • @JakeM It's `IF_NAMESIZE` with the underscore. – MicroVirus Jun 11 '16 at 10:17
  • Whilst the above answer does fix the narrow problem, it wont work for using any other functions/etc from that header file. The problem is because I am compiling with `--std=c11`. This question describes the problem and the solution: http://stackoverflow.com/questions/10433982/why-does-c99-complain-about-storage-sizes – sazr Jun 11 '16 at 10:36