Reputation: 13
So I have made a method using semaphores.
My program opens with
#include <pthread.h>
#include <semaphore.h>
And my make file is
officeHours: officeHours.c
gcc -o officeHours officeHours.c -lpthread -lrt
EDIT: added -lrt....no change
However when I make the file it finds can't find the symbols for
sem_destroy sem_getvalue sem_init sem_post sem_wait
why is this?
Edit: output from "make officeHours"
cc -o officeHours officeHours.c
"officeHours.c", line 4: warning: invalid white space character in directive
"officeHours.c", line 5: warning: invalid white space character in directive
"officeHours.c", line 41: warning: argument #3 is incompatible with prototype:
prototype: pointer to function(pointer to void) returning pointer to void : "/usr/include/pthread.h", line 197
argument: pointer to void
"officeHours.c", line 68: warning: argument #3 is incompatible with prototype:
prototype: pointer to function(pointer to void) returning pointer to void : "/usr/include/pthread.h", line 197
argument: pointer to void
Undefined symbol first referenced in file
sem_destroy officeHours.o
sem_getvalue officeHours.o
sem_init officeHours.o
sem_post officeHours.o
sem_wait officeHours.o
Upvotes: 1
Views: 788
Reputation: 3122
You need to link with the librt
library.
This library contains POSIX realtime extensions.
officeHours: officeHours.c
gcc -o officeHours officeHours.c -lpthread -lrt
If you look at the man page for sem_init(3RT)
:
cc [ flag... ] file... -lrt [ library... ]
#include <semaphore.h>
int sem_init(sem_t *sem, int pshared, unsigned int value);
Upvotes: 1