簡體   English   中英

getline函數的類型沖突

[英]conflicting types for getline function

我的代碼塊中有一個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 <stdio.h> ,此錯誤消息將消失。 但是,如果在源代碼中使用POSIX的getline()您可能會感到困惑,因為它將被您的源代碼代替。

您需要為getline函數選擇一個不同的名稱,因為標准clib中已經有一個getline

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM