"implicit declaration of function" in utarray.h(uthash 的一部分)

"implicit declaration of function" in utarray.h (part of uthash)

我正在为一个项目使用 utarray(uthash library 的一部分)。每当我包含它时,我都会收到以下错误:

utarray.h:221:3: error: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]

不可否认,我在编译时使用了一些非常激进的标志 (-Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99),但我根本不明白为什么这应该是一个错误。 strdupstring.h 中定义(根据 man strdup),这在 utarray.h.

中非常清楚地包含在内

我做错了什么? Google 没有帮助。 (显然没有其他人试图用这些标志编译 utarray.h?)

这是一个编译失败的示例文件(使用 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;
}

版本:gcc 4.9.2、glibc 2.21、uthash 1.9.9

问题是strdup() is not a c standard function it's a POSIX函数,用strdup()的时候不能用-std=c99,除非在编译命令中加入下面的-D_POSIX_C_SOURCE=200809L

gcc -Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99 -D_POSIX_C_SOURCE=200809L

我和 strdup) 有同样的错误,所以我添加了虚拟原型语句

char * strdup(char *) ; 

我没有再收到错误消息。