getline函数的类型冲突 [英] conflicting types for getline function
问题描述
我的代码块中有一个getline函数的函数,但是在编译make文件时出现以下错误:
I have a function for getline function in my code block.But while compiling the make file i get the following error:
cc -DMAIN -c -o terp.o terp.c
terp.c:130:15: error: conflicting types for ‘getline’
In file included from terp.c:2:0:
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here
make: *** [terp.o] Error 1
terp.c在130左右的部分:
The part terp.c around 130:
PRIVATE char *getline()
{
static int first_time_called=1;
if(!first_time_called)
return 0;
first_time_called=0;
return Expr;
}
推荐答案
至少有三种可能的解决方案.
There are at least three possible solutions.
-
由于
getline()
不在标准c库中,而是在POSIX(和GLIBC)中,可以切换为禁用其扩展名(它们在GCC中默认启用).尝试使用命令cc -DMAIN -std = c99 -c -o terp.o terp.c
编译源代码.
As
getline()
is not in standard c library, but in POSIX (and GLIBC), there could be switch to disable its extension (they enabled by default in GCC). Try compiling your source with commandcc -DMAIN -std=c99 -c -o terp.o terp.c
.
如果需要POSIX扩展,则必须将 getline()
函数重命名为其他名称.
If you need POSIX extensions, you have to rename your getline()
function to something else.
从您的源中删除<code> #include< stdio.h> ,此错误消息将消失.但是,如果在源代码中使用POSIX的 getline()
,您可能会感到困惑,因为它将被您的源代码代替.
Remove #include <stdio.h>
from your source, this error message will disappear. But you may become confused if POSIX's getline()
is used in your source code, as it will be replaced by yours.
这篇关于getline函数的类型冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!