Reputation: 99
I am porting window mutexes to linux using pthreads and compiling with gcc. I came across WaitForSingleObject
function on windows. I am trying to use pthread_mutex_timedlock
to lock the mutex for an x amount of seconds just like WaitForSingleObject
.
I included the time.h
and pthread.h
files but when I try to compile, I get an undefined reference to pthread_mutex_timedlock
error. When I take an argument out of pthread_mutex_timedlock
and try to compile, I get
too few arguments to function "pthread_mutex_timedlock"
I am confused as to why I am getting the undefined reference error. A snippet of my code is below:
#include <pthread.h>
#include <time.h>
int dwWaitResult;
struct timespec timeout;
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec = 10;
dwWaitResult = pthread_mutex_timedlock(mutexArray[mutexIndex], &timeout);
Upvotes: 1
Views: 1177
Reputation: 99
undefined reference means that yo udo not link agains pthread lib; did you try adding -lpthread? @OznOg
OznOg answered my question. I just needed to use -pthread when compiling. Thank you!!
Upvotes: 1