title: getting error in c program "undefined reference to gettid"
body: <p><em>This is my thread sub routine...</em>
  Here, I am creating 4 threads and passing structure as a argument to thread sub routine. </p>
  
  <p>I am trying to print thread id with <code>getid()</code> function,</p>
  
  <p>I am getting error saying <strong>"undefined reference to gettid()".</strong></p>
  
  <p>I have added necessary header files...</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #define ARRAYSIZE 17
  #define NUMTHREADS 4
  
  struct ThreadData {
          int start, stop;
          int* array; 
  };
  
  void* squarer(void* td) 
  {
       struct ThreadData* data=(struct ThreadData*) td;
  
       int start=data-&gt;start;
       int stop=data-&gt;stop;
       int* array=data-&gt;array;
       int i;
       pid_t tid1;
  
       tid1 = gettid(); //error at this statement//`
       printf("tid : %d\n",tid1);
  
       for (i=start; i&lt;stop; i++) {
           sleep(1);
           array[i]=i*i;
           printf("arr[%d] = [%d]\n",i,array[i]);
       } 
     return NULL;
  }
  
  int main(void) {
      int array[ARRAYSIZE];
      pthread_t thread[NUMTHREADS];
      struct ThreadData data[NUMTHREADS];
      int i;
  
      int tasksPerThread=(ARRAYSIZE+NUMTHREADS-1)/NUMTHREADS;
  
      for (i=0; i&lt;NUMTHREADS; i++) {
              data[i].start=i*tasksPerThread;
              data[i].stop=(i+1)*tasksPerThread;
              data[i].array=array;
      }
  
      data[NUMTHREADS-1].stop=ARRAYSIZE;
  
      for (i=0; i&lt;NUMTHREADS; i++) {
              pthread_create(&amp;thread[i], NULL, squarer, &amp;data[i]);
      }
  
      for (i=0; i&lt;NUMTHREADS; i++) {
              pthread_join(thread[i], NULL);
      }
  
      for (i=0; i&lt;ARRAYSIZE; i++) {
              printf("%d ", array[i]);
      }
      printf("\n");
  
      return 0;
  }
  </code></pre>