The issue is your usage of the -std=c99 option. Since strndup()isn't part of C99, and you're asking the compiler to go into standards compliant mode, it won't provide the prototype for it. It still links of course, because your C library has it.
While you may be able to coax gcc into providing it by specifying feature macros yourself, I'd say it doesn't make much sense to be in C99 compliance mode and ask for GNU extensions for example. gcc already provides a mode for this, which will solve your warning: -std=gnu99.
So I'd need to, eg, #define POSIX_C_SOURCE 200809Lbefore the first #include. see man 7 feature_test_macros
回答3:
strndup is a GNU extension, so you need to compile with -D_GNU_SOURCE on the command line, or stick a #define _GNU_SOURCE 1 in your source files before the #include lines
回答4:
This happened to me, and I added #define _XOPEN_SOURCE 500 and the warning went away.