gcc 编译getline函数报错:error:implicit declaration of function

博客介绍了getline()函数,它在<stdio.h>中声明,并非标准ANSI函数,而是GNU扩展的,还提到为正确使用该函数需按特定方式操作。

    getline()是在<stdio.h>中声明的,但是这个函数不是标准的ANSI函数,而是由GNU扩展的,因此为了正确使用,需要如下所示:

#define _GNU_SOURCE
#include <stdio.h>
 
/* functions like getline() and getdelim() should be defined now */


http.c: In function ‘accept_request’: http.c:45:16: warning: implicit declaration of function ‘get_line’; did you mean ‘getline’? [-Wimplicit-function-declaration] 45 | numchars = get_line(client, buf, sizeof(buf)); | ^~~~~~~~ | getline http.c:62:9: warning: implicit declaration of function ‘unimplemented’ [-Wimplicit-function-declaration] 62 | unimplemented(client); | ^~~~~~~~~~~~~ http.c:115:9: warning: implicit declaration of function ‘not_found’ [-Wimplicit-function-declaration] 115 | not_found(client); | ^~~~~~~~~ http.c:128:13: warning: implicit declaration of function ‘serve_file’ [-Wimplicit-function-declaration] 128 | serve_file(client, path); | ^~~~~~~~~~ http.c:131:13: warning: implicit declaration of function ‘execute_cgi’ [-Wimplicit-function-declaration] 131 | execute_cgi(client, path, method, query_string); | ^~~~~~~~~~~ http.c: At top level: http.c:144:6: warning: conflicting types for ‘execute_cgi’; have ‘void(int, const char *, const char *, const char *)’ 144 | void execute_cgi(int, const char *, const char *, const char *); | ^~~~~~~~~~~ http.c:131:13: note: previous implicit declaration of ‘execute_cgi’ with type ‘void(int, const char *, const char *, const char *)’ 131 | execute_cgi(client, path, method, query_string); | ^~~~~~~~~~~ http.c:151:6: warning: conflicting types for ‘not_found’; have ‘void(int)’ 151 | void not_found(int); | ^~~~~~~~~ http.c:115:9: note: previous implicit declaration of ‘not_found’ with type ‘void(int)’ 115 | not_found(client); | ^~~~~~~~~ http.c:153:6: warning: conflicting types for ‘serve_file’; have ‘void(int, const char *)’ 153 | void serve_file(int, const char *); | ^~~~~~~~~~ http.c:128:13: note: previous implicit declaration of ‘serve_file’ with type ‘void(int, const char *)’ 128 | serve_file(client, path); | ^~~~~~~~~~ http.c:157:6: warning: conflicting types for ‘unimplemented’; have ‘void(int)’ 157 | void unimplemented(int); | ^~~~~~~~~~~~~ http.c:62:9: note: previous implicit declaration of ‘unimplemented’ with type ‘void(int)’ 62 | unimplemented(client); | ^~~~~~~~~~~~~ http.c: In function ‘main’: http.c:673:24: warning: passing argument 1 of ‘accept_request’ makes pointer from integer without a cast [-Wint-conversion] 673 | accept_request(client_sock); | ^~~~~~~~~~~ | | | int http.c:28:27: note: expected ‘void *’ but argument is of type ‘int’ 28 | void accept_request(void *arg) | ~~~~~~^~~ http.c: In function ‘execute_cgi’: http.c:403:17: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 403 | write(cgi_input[1], &c, 1);
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值