求助!有关gcc编译的问题!急!!!!!!!!
我编写了一个程序,当中用了socket套接口,代码如下:#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define SIZE 40
#define SERVER_PORT 8100
int main(int argc,char *argv[]){
int sockfd,addrlen;
struct sockaddr_in server;
void udpconn(int sockfd,struct sockaddr_in *addr,int len);
sockfd=sock(AF_INET,SOCK_DGRAM,0);
if(sockfd<0){
perror("sock error:");
exit(1);
}
bzero(&server,sizeof(server));
server.sin_family=AF_INET;
server.sin_port=htons(SERVER_PORT);
inet_aton(argv,server.sin_addr);
addrlen=sizeof(server);
udpconn(sockfd,&server,addrlen);
exit(0);
}
void udpconn(int sockfd,struct sockaddr_in *addr,int len){
char msg;
printf("Enter the word about information you want to know: ");
fgets(msg,40,stdin);
if(msg!=NULL){
sendto(sockfd,msg,strlen(msg),0,(struct sockaddr *)addr,len);
}
}
当我编译时:
gcc server.c
总会出现类似这样的错误:
/tmp/cc2wpt1M.o(.text+0x1a): In function `main':
: undefined reference to `sock'
collect2: ld returned 1 exit status
C的语法应该没错啊,是不是用gcc编译socket编写的程序时要加什么选项???
我写的这个程序很急要交,在此谢谢各位了,谢谢谢谢,望大家指教 shi socket, bu shi sock 谢谢你啊,解决了,咳,犯了那么低级的错误,真是惭愧啊!!!!!!!!!! sock(AF_INET,SOCK_DGRAM,0);
……
socket(AF_INTE,SOCK_DGRAM,0);
页:
[1]