Note that there are some explanatory texts on larger screens.

plurals
  1. POerror " undefined reference to " at compile time
    text
    copied!<p>when I compile this file it keeps giving me </p> <pre><code>Undefined reference to size Undefined reference to file </code></pre> <p>I compiled it twice in the second time it give me both error, when the first time it give me only the second error.</p> <p>can I know exactly what is the problem and how I can solve it? </p> <p>ps: i use <code>gcc -o ser server.c</code> to compile </p> <p>Sorry I had problem with my Net</p> <pre class="lang-c prettyprint-override"><code> #include&lt;stdio.h&gt; #include&lt;errno.h&gt; #include&lt;arpa/inet.h&gt; #include&lt;string.h&gt; #include&lt;netinet/in.h&gt; #include&lt;sys/types.h&gt; #include&lt;sys/socket.h&gt; #include&lt;stdlib.h&gt; #include&lt;fcntl.h&gt; #define Max_len 1049 void error (char * str) { perror(str); exit(0); } </code></pre> <p>this the complete code</p> <pre><code>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&lt;=22000) || (portno&gt;=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 *)&amp;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 *)&amp;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 *)&amp;cliaddr ,sizeof(cliaddr)); //clear the previus client information clilen=sizeof(cliaddr); //client informaton container connfd=accept(listenfd,(struct sockaddr *)&amp;cliaddr,&amp;clilen); if(connfd&lt;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 &lt; 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)&gt;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() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload