getline函数的冲突类型

时间:2014-03-24 15:41:27

标签: c makefile

我的代码块中有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;
 }

2 个答案:

答案 0 :(得分:2)

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

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

  2. 如果您需要POSIX扩展程序,则必须将getline()功能重命名为其他功能。

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

答案 1 :(得分:1)

您需要为getline函数选择其他名称,因为标准clib中已有getline