andandandand
andandandand

Reputation: 22260

Why is this semaphore code failing?

#include <semaphore.h>


sem_t mutex;


int main (int argc, char * argv[])
{



sem_init (&mutex,0,1); 

}

I'm getting:

/tmp/ccAMFxDX.o: In function `main':
programaservidor.c:(.text+0x86): undefined reference to `sem_init'
collect2: ld returned 1 exit status

Upvotes: 2

Views: 6178

Answers (3)

icanhasserver
icanhasserver

Reputation: 1064

As stated in the man page, you have to link with either -lrt or -pthread.

Upvotes: 1

SiegeX
SiegeX

Reputation: 140227

Per the sem_init() man page

Link with -lrt or -pthread.

As in gcc your_code.c -lpthread -o your_code

Upvotes: 5

Related Questions