title: Some problems with using semaphores
body: <p>Right now I'm working on my project and I have a question about initialization of semaphores. Actually I'm programming on Mac OS X, but I tried to compile me project on Linux and it doesn't compile. On OS X it compiles but every time just crashing at the moment of initialization. </p>
  
  <pre><code>sem_t *mutex_1, *mutex_2, *mutex_3, *reader, *writer;
  
  int initialization_semaphores (void) 
  {
      int ERROR = EOK;
      if ((mutex_1 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
          ERROR = ESEM;
      if ((mutex_2 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
          ERROR = ESEM;
      if ((mutex_3 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
          ERROR = ESEM;
      if ((reader = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
          ERROR = ESEM;
      if ((writer = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
          ERROR = ESEM;
  
      if (ERROR == EOK) {
          if (sem_init(mutex_1, 1, 1) == -1)
              ERROR = ESEM;
          if (sem_init(mutex_2, 1, 1) == -1)
              ERROR = ESEM;
          if (sem_init(mutex_3, 1, 1) == -1)
              ERROR = ESEM;
          if (sem_init(reader, 1, 1) == -1)
              ERROR = ESEM;
          if (sem_init(writer, 1, 1) == -1)
              ERROR = ESEM;
      }
  }
  </code></pre>
  
  <p>When I tried to compile it on linux I see this: </p>
  
  <pre><code>/tmp/ccmkN9G7.o: In function `initialization_semaphores':
  readerWriter.c:(.text+0x1a2): undefined reference to `sem_init'
  readerWriter.c:(.text+0x1cb): undefined reference to `sem_init'
  readerWriter.c:(.text+0x1f4): undefined reference to `sem_init'
  readerWriter.c:(.text+0x21d): undefined reference to `sem_init'
  readerWriter.c:(.text+0x246): undefined reference to `sem_init'
  readerWriter.c:(.text+0x275): undefined reference to `shm_open'
  </code></pre>
  
  <p>Is it right? :</p>
  
  <pre><code>int ERROR = EOK;
  mutex_1 = sem_open("mutex1", O_CREAT, S_IRUSR | S_IWUSR, 1);   
  mutex_2 = sem_open("mutex2", O_CREAT, S_IRUSR | S_IWUSR, 1);  
  mutex_3 = sem_open("mutex3", O_CREAT, S_IRUSR | S_IWUSR, 1); 
  reader = sem_open("reader", O_CREAT, S_IRUSR | S_IWUSR, 1); 
  writer = sem_open("writer", O_CREAT, S_IRUSR | S_IWUSR, 1);   
  </code></pre>