UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » General
  • » Error: Undefined Symbol ..... First referenced in file......

#1 2003-01-02 07:37 AM

dipesh
Member
Registered: 2002-12-27
Posts: 2

Re: Error: Undefined Symbol ..... First referenced in file......

Hi,

Below is the code that i hv taken from some site(never done socket programming in C so having a taste of it) n trying to run it.

But i got the errors which i m not able to resolve.

Source code

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
        struct  hostent *h;

        if(argc != 2)
        {
                fprintf(stderr, "usage: getip address\n");
                exit(1);
        }

        if( (h = gethostbyname(argv[1]))== NULL)
        {
                herror("gethostbyname");
                exit(1);
        }


compile

apollo 155: cc GETIP.c

Error

Undefined                       first referenced
symbol                             in file
gethostbyname                       GETIP.o
inet_ntoa                           GETIP.o
herror                              GETIP.o
ld: fatal: Symbol referencing errors. No output written to a.out


Please throw some light to resolve this error.
My guess are
1) Is any library file missing as it is giving error like this.
2) If yes, from where i will get the library files.
3) Do i have to keep these library files (in case if i get it from somewhere ) in the current directory. Because i m running this program on one server which is at remote location. I am having my user id there and trying to run this program.

PLEASE SUGGEST SOMETHING.

I HOPE I WILL GET THE ANSWER TO MY QUERY.

Regards
Dipesh

Offline

#2 2003-01-02 02:27 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Error: Undefined Symbol ..... First referenced in file......

It sounds like you're on one of those wacky systems which keep their
socket functions in a separate library...  I hate those systems... ;-)

Try adding "-lsocket" and/or "-lnsl" to the link command line...

Offline

#3 2003-01-03 05:33 AM

dipesh
Member
Registered: 2002-12-27
Posts: 2

Re: Error: Undefined Symbol ..... First referenced in file......

Thanx for answering my query !!

When i used "-lnsl" to the link command line... it worked...my code got compiled properly and i go the output.
As shown in my code in my previous mail where i hv used "herror" function ...so i was getting error during compilation. After commenting that line my program ran properly. Is that function defined in some other library file ?. For running every program do i hv to give "lnsl" option ?

When i used  "-lsocket"I still got the errors like......
Undefined                       first referenced
symbol                             in file
gethostbyname   GETIP.o  (symbol belongs to implicit dependency /usr/lib/libnsl.so.1)
inet_ntoa                   GETIP.o  (symbol belongs to implicit dependency /usr/lib/libnsl.so.1)
ld: fatal: Symbol referencing errors. No output written to a.out

Thanx for solving my problem.

Regards !!
Dipesh

Offline

#4 2017-03-02 07:35 AM

Ebith
Guest

Re: Error: Undefined Symbol ..... First referenced in file......

RobSeace wrote:

It sounds like you're on one of those wacky systems which keep their
socket functions in a separate library...  I hate those systems... ;-)

Try adding "-lsocket" and/or "-lnsl" to the link command line...

Thanks a lot. Though it was an old post, it helped to fix my problem in one of the wacky system.

  • Index
  • » General
  • » Error: Undefined Symbol ..... First referenced in file......

Board footer

Powered by FluxBB