- 论坛徽章:
- 0
|
网络编程中的一个错误,搞不定,求助大家
原帖由 "minichen" 发表:
1.exit()是在stdlib.h中定义,以后哪个函数找不到定义,用man看一下这个函数,里面有它所需要的头文件。
2.源文件最后一行最好回车。
我查过的,后来加入#include <stdlib.h>;后会出现下面的错误
[root@BillingServer unix]# gcc -o PRG6_1 PRG6_1.C
PRG6_1.C:89:2: warning: no newline at end of file
/tmp/ccGdH2Xw.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
文件名换成小写的c
[root@BillingServer unix]# gcc -o PRG6_1 PRG6_1.c
PRG6_1.c:14: parse error before "sockaddr_in"
PRG6_1.c:66: parse error before "sockaddr_in"
PRG6_1.c: In function `process_cli':
PRG6_1.c:71: `client' undeclared (first use in this function)
PRG6_1.c:71: (Each undeclared identifier is reported only once
PRG6_1.c:71: for each function it appears in.)
PRG6_1.c:74: `connectfd' undeclared (first use in this function)
PRG6_1.c:79: `for' loop initial declaration used outside C99 mode
PRG6_1.c:89:2: warning: no newline at end of file
有网友提出是否是这个函数的问题:
void process_cli(int connectfd, struct sockaddr_in client);
可是后来我把sockaddr_in结构体的定义拷过来
- struct sockaddr_in{
- unsigned short sin_family;
- unsigned short int sin_port;
- struct in_addr sin_addr;
- unsigned char sin_zero[8];
- }
复制代码
却出现15: redefinition of `struct sockaddr_in'
的错误。
请教下面三个问题:
1.client变量用struct sockaddr_in来定义有问题吗?
2.connectfd只不过是个socket description,只不过是个int型的数,这样也错?
3.for循环问题已经解决,居然是把i的定义放到外一层就OK |
|