undefined symbol inet_addr

Started by
2 comments, last by rajend3 16 years, 9 months ago
I'm having trouble with this code. I just wanted to see if what I wrote so far had any problems and it did; this is the error I got: Undefined first referenced symbol in file inet_addr client.o This is the code: #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <string.h> #include <errno.h> #define SOURCEPORT 3490 int main() { struct sockaddr_in sourceAddr; sourceAddr.sin_family = AF_INET; sourceAddr.sin_port = htons(SOURCEPORT); sourceAddr.sin_addr.s_addr = inet_addr("10.12.110.57"); memset( sourceAddr.sin_zero, '\0', sizeof sourceAddr.sin_zero); return 0; } Is there a typo in my code or is there an include problem?
Advertisement
I'm not really much of a C person, but it looks to me like you are calling a function called "inet_addr" which is not defined in any of the header files you include. Which is weird since it should be in <arpa/inet.h>. If this is a linker error, I guess you are not linking the program properly.
Given the error is an undefined symbol referenced in an .o file, it looks like a linker error. Depending on your system you may need one or more of -lnsl -lsocket -lresolv as additional libraries.
Thanks for the help, I had to link it with -lnsl and it compiled.

This topic is closed to new replies.

Advertisement