I am compiling a program that contains mutex semaphores from the pthread library but when i compile using the -lpthread flag I am getting an undefined reference error.
gcc -lpthread prodcon.c
/tmp/ccESOlOn.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
The syntax for the mutex lock is like so:
pthread_mutex_t mutex1;
is a global declaration so that it can be used by multiple threads. within the functions I am calling the mutex like so:
pthead_mutex_lock(&mutex1);
pthead_mutex_unlock(&mutex1);
But i am getting the compiler error, I also tried compiling with the -pthread flag
gcc -pthread prodcon.c
/tmp/cc6wiQPR.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
I have searched for answers but am at a loss and would appreciate any help with figuring out why it has an undefined reference when I am linking in the library that contains the mutex locks.