tinyhttpd编译出错的解决方法

book@ubuntu:/home/demo/tinyhttpd-0.1.0$ make
gcc -W -Wall -lsocket -lpthread -o httpd httpd.c
httpd.c: In function ‘startup’:
httpd.c:437:34: warning: pointer targets in passing argument 3 of ‘getsockname’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:119:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c: In function ‘main’:
httpd.c:491:24: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness [-Wpointer-sign]
/usr/include/i386-linux-gnu/sys/socket.h:214:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int *’
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
/usr/bin/ld: cannot find -lsocket
collect2: ld returned 1 exit status
make: *** [httpd] Error 1






book@ubuntu:/home/demo/tinyhttpd-0.1.0$ gcc -o httpd httpd.c -lpthread
httpd.c: In function ‘main’:
httpd.c:495:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(int)’
httpd.c:495:2: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’




有上面错误知:pthread_create  传递的参数有问题。


源码修改:
1、源码495行 ,改为 if (pthread_create(&newthread , NULL, accept_request, (void*)&client_sock) != 0)


2、33行改为 void* accept_request(void *); 相应的该函数的实现也要做出修改:
void *accept_request(void *pclient)
{
int client = *(int *)pclient;

...
}





https://baike.baidu.com/item/apache/6265
http://blog.csdn.net/wenqian1991/article/details/46048987
https://www.cnblogs.com/chenyang920/p/5610052.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alen.Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值