Jake M Jake M - 5 months ago 16
Linux Question

Does POSIX if.h require a library to use

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?

Answer

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.