title: Erros while using pthread_create and pthread_detach
body: <p>I'm programming a server that can receive messages from multiple clients, so I'm using multithreading but I'm having some trouble with warnings and errors that do not allow my code to sucessfully compile. I've searched and still can't find what is causing these errors.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;resolv.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;strings.h&gt;
  
  #define ADRRESS "127.0.0.1"
  #define PORT 9999
  
  
  void *receive_tcp(void *clientfd)
  {
      char buffer1[7];
      //char *buffer2;
      int n, i;
  
      n = read(clientfd, buffer1, sizeof(buffer1));
  
      for(i=0;i&lt;n;i++)
      {
          printf("%c", buffer1[i]);
      }
  }
  
  void main()
  {
      int sock;
      struct sockaddr_in s1;
      char buffer1[7];
      int n, i;
  
      printf("A criar socket...\n");
  
      if ((sock = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)
      {
          printf("Erro ao criar socket.\n");
          exit(1);
      }
  
      bzero(&amp;s1, sizeof(s1));
      s1.sin_family = AF_INET;
      s1.sin_port = htons(PORT);
      s1.sin_addr.s_addr = INADDR_ANY;
  
      printf("A ligar ao socket...\n");
  
      if (bind(sock, (struct sockaddr*)&amp;s1, sizeof(s1)) != 0)
      {
          printf("Erro ao ligar socket.\n");
          exit(1);
      }
  
      printf("A configurar socket...\n");
  
      if (listen(sock, 10) != 0)
      {
          printf("Erro ao configurar socket.\n");
          exit(1);
      }
      printf("A entrar no ciclo...\n");
  
      while(1)
      {
          int clientfd;
          struct sockaddr_in client_addr;
          int addrlen=sizeof(client_addr);
  
          pthread_t thread1;
  
          printf("À espera de uma nova ligação...\n");
          clientfd = accept(sock, (struct sockaddr*)&amp;client_addr, &amp;addrlen);
          /*n = read(clientfd, buffer1, sizeof(buffer1));
  
          for(i=0;i&lt;n;i++)
          {
              printf("%c", buffer1[i]);
          }*/
  
          pthread_create(&amp;thread1, 0, receive_tcp, clientfd);       
          pthread_detach(thread1);
  
      }
  }
  </code></pre>
  
  <p>And here are the errors:
  </p>
  
  <pre class="lang-none prettyprint-override"><code>serv.c: In function ‘main’:
  serv.c:82:3: warning: passing argument 4 of ‘pthread_create’ makes pointer from integer without a cast [enabled by default]
     pthread_create(&amp;thread1, 0, receive_tcp, clientfd);       
     ^
  In file included from serv.c:6:0:
  /usr/include/pthread.h:244:12: note: expected ‘void * __restrict__’ but argument is of type ‘int’
   extern int pthread_create (pthread_t *__restrict __newthread,
              ^
  /tmp/ccxdvY86.o: In function `main':
  serv.c:(.text+0x1fe): undefined reference to `pthread_create'
  serv.c:(.text+0x20a): undefined reference to `pthread_detach'
  collect2: error: ld returned 1 exit status
  </code></pre>