I'm trying to solve a problem with semáforos
, but when I try to use the sem_init()
function I get an error saying that there is undefined reference,
Can you tell me why?
I have the semáforos
library included.
Code (C):
#include<semaphore.h>
#include<sys/sem.h>
int pos_escrita;
int pos_leitura;
int buffer[10]; //capacidade para 10
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
sem_t vazio;
sem_t cheio;
// IDs das threads
int id_produtores[100];
int id_consumidores[10];
void init()
{
sem_init(&vazio, 0, 10);
sem_init(&cheio, 0, 0);
pos_escrita = 0;
pos_leitura = 0;
}
int main()
{
int i;
init();
pthread_t threads[2]; // nº de threads
for(i=0; i<10;i++)
{
}
printf("\n");
return 0;
}
The displayed error was:
/tmp/ccTcI1EU.o: In function init ': f.c :(. text + 0x1e): undefined reference to sem_init 'f.c :(. text + 0x3a): undefined reference to sem_init 'collect2: ld returned 1 exit status