How to fix "undefined reference to" problem?

Hi

I have a code shown below, but when I use “qcc -o udpclient udpclient.c” to compile the file, I was told:
udpclient.o: In function main': udpclient.o(.text+0x3a): undefined reference to socket’
udpclient.o(.text+0xb6): undefined reference to sendto' udpclient.o(.text+0xd1): undefined reference to recvfro
cc: /usr/qnx632/host/qnx6/x86/usr/bin/ntox86-ld error 1

Could some one help me?
Thanks in advance.

 /* file: client.c */
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>  

 #include <sys/socket.h>  

 #include <netinet/in.h>  

 #include <netdb.h>


 int main(int argc, char **argv)  

 {  

     int fd;  

     struct sockaddr_in address;  

     int address_len;  

     char line[80] = "Client to Server string!\n";  

     int n;  



     fd = socket(AF_INET, SOCK_DGRAM, 0);



     bzero(&address, sizeof(address));  

     address.sin_family = AF_INET;  

     address.sin_addr.s_addr = inet_addr("192.168.10.56");  

     address.sin_port = htons(5000);  

     address_len = sizeof(address);  



     sendto(fd, line, strlen(line)+1, 0, (struct sockaddr *)&address, sizeof(address));   

     n = recvfrom(fd, line, 80, 0, NULL, NULL);  

     printf("received %d:%s", n, line);  

 }

You have to link in extra libraries, like socket. Try adding “-l socket” to your qcc command line.

Thanks a lot. It works.