隐式声明使用-std = c99
我得到这个警告:( -std = c99 -pedantic
)
warning: implicit declaration of function ‘strndup’ [-Wimplicit-function-declaration]
但我正在导入这些库:
but I'm importing these libs:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
那又怎样? :($ /
So what?! :(
// file.c:
#include "file.h"
strndup(...)
// file.h:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
问题在于你对 -std = c99
选项的使用,因为 strndup()
它是C99的一部分,并且你要求编译器进入符合标准的模式,它不会提供它的原型。当然,它仍然是链接的,因为你的C库有它。
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.
虽然您可以通过自己指定功能宏来指令 gcc
来提供它,但我认为它没有什么意义例如: gcc
已经为此提供了一种模式,它将解决您的警告: -std = gnu99
。
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
.