title: Linker can't find semaphore functions
body: <p>I'm trying to make a C programm, that will execute subprocesses, which will be interact using semaphore. 
  Then I compile code, gcc throw referencing error - because it doesn't know about functions "sem_init", "sem_post" and "sem_wait", even though I include semaphore.h library.</p>
  
  <p>Here's how it look:</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;semaphore.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;unistd.h&gt;
  
  #define LETTER_COUNT 26
  #define THREADS 2
  
  char letter[LETTER_COUNT] = "aBCDefghiJklMNoPqrsTuvWxyZ";
  
  pthread_t t[THREADS];
  sem_t sem[THREADS];
  
  void print_letter(void) {
      //print string
  }
  
  void* reorder(void* d) {
      (void)d;
      //do some work
      return NULL;
  }
  
  void* switch_case(void* d) {
      (void)d;
      //do some work
      return NULL;
  }
  
  int main(void) {
      int i;
      for(i = 0; i &lt; THREADS; i++) {
          if(sem_init(&amp;sem[i], 0, 0) == -1) {
              perror("sem_init");
              return -1;
          }
      }
      pthread_create(&amp;t[0], NULL, reorder, NULL);
      pthread_create(&amp;t[1], NULL, switch_case, NULL);
      while(1) {
          i = (i + 1) % (THREADS - 1);
          sem_post(&amp;sem[i]);
          sem_wait(&amp;sem[2]);
          print_letter();
          sleep(1);
      }
      return 0;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>gcc -Wall task4.c -o task4.o
  Undefined                       first referenced
   symbol                             in file
  sem_init                            /var/tmp//cc0i56ka.o
  sem_post                            /var/tmp//cc0i56ka.o
  sem_wait                            /var/tmp//cc0i56ka.o
  ld: fatal: symbol referencing errors. No output written to task4.o
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I'm trying to find some information about this problem, but I can't find any working solutions. Maybe I should use some compilation flag (like -lsocket)?</p>