Solved

undefined reference to `sem_init'

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

920 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

16 Experts available now in Live!

Get 1:1 Help Now