Solved

undefined reference to `sem_init'

Posted on 2006-10-29
2
5,205 Views
Last Modified: 2012-06-21
#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. )
0
Comment
Question by:william007
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 17829588
you have to link in the library when compiling : try adding -lpthreads to the compile command
0
 
LVL 9

Author Comment

by:william007
ID: 17853552
Thanks=)
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question