I'm using utarray (part of the uthash library) for a project. Whenever I include it, I get the following error:
utarray.h:221:3: error: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
Admittedly, I use some pretty aggressive flags when compiling (-Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99), but I don't understand why this should be an error at all. strdup is defined in string.h (according to man strdup) which is very clearly included from utarray.h.
What am I doing wrong? Google was no help. (apparently nobody else tries to compile utarray.h with these flags?)
Here's an example file that fails to compile (using gcc -Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99 scratch.c).
#include "utarray.h"
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
return 0;
}
versions: gcc 4.9.2, glibc 2.21, uthash 1.9.9
The problem is that
strdup()is not a c standard function it's a POSIX function, you can't use-std=c99when you usestrdup()unless you add the following-D_POSIX_C_SOURCE=200809Lto the compilation command