title: Compile a static binary which code there a function gethostbyname
body: <p>How to resolve compile a static binary which code include a function gethostbyname and if compiled without warning like this:</p>
  
  <blockquote>
    <p>warning: Using 'gethostbyname' in statically linked applications
    requires at runtime the shared libraries from the glibc version used
    for linking</p>
  </blockquote>
  
  <p>I compile on ubuntu 12.04 with command:</p>
  
  <pre><code>$ gcc -static lookup.c -o lookup
  </code></pre>
  
  <p>This is code for lookup.c:</p>
  
  <pre><code>  /* lookup.c */
  
    #include &lt;stdio.h&gt;
    #include &lt;unistd.h&gt;
    #include &lt;stdlib.h&gt;
    #include &lt;string.h&gt;
    #include &lt;errno.h&gt;
    #include &lt;sys/socket.h&gt;
    #include &lt;netinet/in.h&gt;
    #include &lt;arpa/inet.h&gt;
    #include &lt;netdb.h&gt;
  
    extern int h_errno;
  
    int main(int argc,char **argv) {
       int x, x2;
       struct hostent *hp;
  
       for ( x=1; x&lt;argc; ++x ) {
          hp = gethostbyname(argv[x]);
          if ( !hp ) {
             fprintf(stderr,
                     "%s: host '%s'\n",
                     hstrerror(h_errno),
                     argv[x]);
             continue;
          }
  
          printf("Host %s : \n" ,argv[x]);
          printf(" Officially:\t%s\n", hp-&gt;h_name);
          fputs(" Aliases:\t",stdout);
          for ( x2=0; hp-&gt;h_aliases[x2]; ++x2 ) {
             if ( x2 ) {
                fputs(", ",stdout);
               }
          fputs(hp-&gt;h_aliases[x2],stdout);
          }     
          fputc('\n',stdout);
          printf(" Type:\t\t%s\n",
                 hp-&gt;h_addrtype == AF_INET
                 ? "AF_INET" : "AF_INET6");
          if ( hp-&gt;h_addrtype == AF_INET ) {
             for ( x2=0; hp-&gt;h_addr_list[x2]; ++x2 ) {
                printf(" Address:\t%s\n",
                       inet_ntoa( *(struct in_addr *)
                        hp-&gt;h_addr_list[x2]));
             }
          }
       putchar('\n');
       }
       return 0;
    }
  </code></pre>
  
  <p>I want to if I check via <code>$ file lookup</code> will get output like this: </p>
  
  <blockquote>
    <p>lookup: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux),
    statically linked, for GNU/Linux 2.6.24,
    BuildID[sha1]=0x6fcb2684ad8e5e842036936abb50911cdde47c73, not stripped</p>
  </blockquote>
  
  <p>Not like this:</p>
  
  <blockquote>
    <p>lookup: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
    dynamically linked (uses shared libs), for GNU/Linux 2.6.24,
    BuildID[sha1]=0xf9f18671751927bea80de676d207664abfdcf5dc, not stripped</p>
  </blockquote>
  
  <p>If you commented with suggested I must use without static because different libc every linux  I knew it, I hope you do not need to comment. 
  Why do I persist in for static? 
  Because there I need to do to mandatory use static, binary files must be static and not dynamic.</p>
  
  <p>I have more than 2 weeks looking for this but so far have not succeeded.</p>
  
  <p>Thanks for help me to resolve my heavy problem.</p>