gpt4 book ai didi

c - utarray.h 中的 "implicit declaration of function"(uthash 的一部分)

转载 作者:太空宇宙 更新时间:2023-11-04 08:29:39 26 4
gpt4 key购买 nike

我正在为一个项目使用 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 中.

我做错了什么?谷歌没有帮助。 (显然没有其他人试图用这些标志编译 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()不是 c 标准函数,它是 POSIX函数,你不能在使用strdup()时使用-std=c99,除非你在编译中添加以下-D_POSIX_C_SOURCE=200809L命令

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

关于c - utarray.h 中的 "implicit declaration of function"(uthash 的一部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28994015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com