Solved

undefined reference to `sem_init'

Posted on 2006-10-29
2
5,156 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
FILE closing 11 68
voltage to force translation ? 8 92
rhel6 C system() call to zip to archive has problems 25 227
Unable to start eclipse ? 17 86
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 and use switch statements in the C programming language.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now