您的位置:首页 > 理论基础 > 计算机网络

tinyhttpd编译出错的解决方法

2018-01-27 14:41 519 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: