隐式声明使用-std = c99 [英] implicit declaration using -std=c99

查看:155
本文介绍了隐式声明使用-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.

这篇关于隐式声明使用-std = c99的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆