Thread: problem in gethostbyname

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    19

    problem in gethostbyname

    hi guys,
    i am newbie of socket programming working on solaries sysetm.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<sys/types.h>
    #include<sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include<errno.h>
    #include<assert.h>
    int main(int argc,char *argv[])
    {
            struct hostent *h;
            assert(argc!=2);
            h=gethostbyname(argv[1]);
            printf("host name %s\n",h->h_name);
            return 0;
    }
    while i am compiling this programm i am getting error's
    Code:
    $cc gethostname.c
    Undefined                       first referenced
     symbol                             in file
    gethostbyname                       gethostname.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    anybody please help me where is error
    ~

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    http://cboard.cprogramming.com/showt...+gethostbyname
    See the example command line, specifying the libraries you need
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    try passing -lnsl to the linker

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM