, когда я скомпилировать этот файл, он продолжает давать мнеошибка «неопределенная ссылка на» во время компиляции
Undefined reference to size
Undefined reference to file
Я составил его дважды во второй раз он дает мне как ошибку, когда первый раз он дал мне только вторая ошибка.
Могу я точно узнать, в чем проблема и как я могу ее решить?
пс: я использую gcc -o ser server.c
компилировать
К сожалению у меня была проблема с моим Net
#include<stdio.h>
#include<errno.h>
#include<arpa/inet.h>
#include<string.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<stdlib.h>
#include<fcntl.h>
#define Max_len 1049
void error (char * str)
{
perror(str);
exit(0);
}
этом полный код
int main (int argc, char ** arg)
{
//------------------------- define data type
int listenfd,connfd,clilen,portno,fil_fd;
char buff[Max_len], *str,f_name[100],car=0xAA;
struct sockaddr_in servaddr,cliaddr;
FILE * file_ptr; //to store the pointer that point to the read file
//------------------------- socket intinalizing
if(argc != 2) //of user forget to insert the port number
error("missing port number to complet establishment\n");
portno=atoi(arg[1]); //convert the port to int and check if it was within the rang
if((portno<=22000) || (portno>=23000))
error("your port number not valid .... pleas insert one in reng (22000,22999)\n");
listenfd=socket(AF_INET,SOCK_STREAM,0); //creat the listing socket
bzero((char *)&servaddr ,sizeof(servaddr));
servaddr.sin_family=AF_INET; //Ipv4
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(portno);
bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr));//bind the liten socket to specific port
listen(listenfd,5);
//-------------------------- server start to wait to handle requests
for(;;)
{
printf("server wait for connections\n");
bzero((char *)&cliaddr ,sizeof(cliaddr)); //clear the previus client information
clilen=sizeof(cliaddr); //client informaton container
connfd=accept(listenfd,(struct sockaddr *)&cliaddr,&clilen);
if(connfd<0)
error("error in accept this connection\n");
//--------------------------------------- //start the secret hand chacking
snprintf(buff,/*sizeof(buff)*/1,"%c",0x55);
write(connfd,buff,sizeof(buff));
//--------------------------------------- //read file name
car=0xAA;
read(connfd,buff,size(buff));
printf("client reply is %c",buff[0]);
if(car==buff[0])
{
printf("wait for file name \n");
// bzero(buff,sizeof(buff));
printf("1#%s\n",buff);
read(connfd,buff,sizeof(buff));
printf("2#%s\n",buff);
strncpy(f_name,buff,sizeof(buff)-1);
printf("file return name is %s\n",buff);
}
else
error("this is not secure client\n");
//-------------------------------------- if file found send 1 else 0
fil_fd=open(f_name,O_RDONLY); //file opent to be read only
if(fil_fd < 0)
{
snprintf(buff, sizeof(buff),"%d",0);
write(connfd,buff,1);
file("file is not found\n"); //retminate connection only
break;
}
else
{
snprintf(buff, sizeof(buff),"%d",1);
write(connfd,buff,1);
printf("file exists.Send 1 to client\nreading and send the deil\n");
//-----------------------------------reading and sending
while(read(buff,1048,fil_fd)>0)
{
printf("%s \n\n",buff);
write(connfd,buff,sizeof(buff)); //sending the file process
}//end of uploading
}//end of if_else
//-------------------------------------------- close file resources " file"
close(fil_fd);
close(connfd);
}//end of for()
//--------------------------------------------prepair the server connection
close(listenfd);
exit(0);
return 0;
}//main()
Можем ли мы увидеть соответствующий фрагмент кода, вызывающий ошибку? Мы ужасные угадывания. –
Не видя никакого кода, мы можем только догадываться. Я предполагаю, что вам не хватает директивы '# include' или нужно связать библиотеку. – jpw
Пожалуйста, отправьте проблемный исходный код. – Mauren