Solved

undefined reference to `sem_init'

Posted on 2006-10-29
2
5,325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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.

617 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