我在一个项目中使用utarray (uthash库的一部分)。每当我包括它时,我都会得到以下错误:
utarray.h:221:3: error: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]诚然,我在编译(-Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99)时使用了一些相当激进的标志,但我不明白为什么这会是一个错误。strdup是在string.h (根据man strdup)中定义的,它非常清楚地包含在utarray.h中。
我做错了什么?谷歌帮不上忙。(显然没有其他人尝试用这些标志编译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
发布于 2015-03-11 17:59:24
问题是strdup()不是c标准函数,它是POSIX函数,除非将以下-D_POSIX_C_SOURCE=200809L添加到编译命令中,否则在使用strdup()时不能使用strdup()
gcc -Wall -Wpedantic -Wextra -Werror -pedantic-errors -std=c99 -D_POSIX_C_SOURCE=200809L发布于 2020-06-01 07:41:45
我对strdup)也有同样的错误,所以我添加了虚拟原型语句
char * strdup(char *) ; 我再也不知道错误信息了。
https://stackoverflow.com/questions/28994015
复制相似问题