您的位置:首页 > 编程语言 > ASP

implicit declaration of function 'asprintf' 警告的解决

2015-07-09 15:03 1291 查看

asprintf使用起来非常方便,但是它是GNU扩展的C函数库,使用的时候经常会有如下警告:

warning: implicit declaration of function 'asprintf' [-Wimplicit-function-declaration]

调查发现asprintf的头文件是stdio.h,在该头文件中

#ifdef __USE_GNU
/* Write formatted output to a string dynamically allocated with `malloc'.
Store the address of the string in *PTR.  */
extern int vasprintf (char **__restrict __ptr, __const char *__restrict __f,
_G_va_list __arg)
__THROW __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
extern int __asprintf (char **__restrict __ptr,
__const char *__restrict __fmt, ...)
__THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
extern int asprintf (char **__restrict __ptr,
__const char *__restrict __fmt, ...)
__THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
#endif

但是__USE_GNU是glibc内容的宏定义,我们不能在自己的代码中定义,因此要怎么解决呢?

解决方法:

在makefile中加入编译选项 -D_GUN_SOURCE

如果是用CMake,需加入add_definitions (-D_GNU_SOURCE)

如果遇到类似因#ifdef __USE_GNU引起的问题,可以通过如上设定尝试解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: