getline函数的冲突类型

我的代码块中有getline函数的函数。但是在编译make文件时我得到以下错误:

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:

  PRIVATE char *getline() { static int first_time_called=1; if(!first_time_called) return 0; first_time_called=0; return Expr; } 

至少有三种可能的解决方案。

  1. 由于getline()不在标准c库中,但在POSIX(和GLIBC)中,可能会切换到禁用其扩展(默认情况下它们在GCC中启用)。 尝试使用命令cc -DMAIN -std=c99 -c -o terp.o terp.c编译源代码。

  2. 如果您需要POSIX扩展,则必须将getline()函数重命名为其他内容。

  3. 从源中删除#include ,此错误消息将消失。 但是如果在您的源代码中使用POSIX的getline()您可能会感到困惑,因为它将由您的代码替换。

您需要为getline函数选择一个不同的名称,因为标准clib中已经有一个getline