undefined reference to `sem_init'

#include <semaphore.h>
#include <unistd.h>

static sem_t count_sem;
int main(int argc, char* argv[]){
sem_init(&count_sem,1,3);
while(1){
      sem_wait(&count_sem);
      fork();
      if(getpid()==0){
      
      }
}
}


I get the following problem when I compile using gcc
/tmp/cc4Pal2o.o: In function `main':
contoller.c:(.text+0x29): undefined reference to `sem_init'
contoller.c:(.text+0x35): undefined reference to `sem_wait'
collect2: ld returned 1 exit status


What is the problem and how to correct it? (My platform is Linux Fedora Core 5. )
LVL 9
william007Asked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
you have to link in the library when compiling : try adding -lpthreads to the compile command
0
 
william007Author Commented:
Thanks=)
0
All Courses

From novice to tech pro — start learning today.