c - no reference to pthread_mutex_lock with -lpthread compiled -


i compiling program contains mutex semaphores pthread library when compile using -lpthread flag getting undefined reference error.

gcc -lpthread prodcon.c /tmp/ccesolon.o: in function `producer': prodcon.c:(.text+0x2e): undefined reference `pthead_mutex_lock' prodcon.c:(.text+0xd6): undefined reference `pthead_mutex_unlock' collect2: ld returned 1 exit status 

the syntax mutex lock so:

pthread_mutex_t mutex1; 

is global declaration can used multiple threads. within functions calling mutex so:

pthead_mutex_lock(&mutex1); pthead_mutex_unlock(&mutex1); 

but getting compiler error, tried compiling -pthread flag

gcc -pthread prodcon.c /tmp/cc6wiqpr.o: in function `producer': prodcon.c:(.text+0x2e): undefined reference `pthead_mutex_lock' prodcon.c:(.text+0xd6): undefined reference `pthead_mutex_unlock' collect2: ld returned 1 exit status 

i have searched answers @ loss , appreciate figuring out why has undefined reference when linking in library contains mutex locks.

order matters, use:

gcc prodcon.c -lpthread  

or better:

gcc -wall -wextra -pedantic -pthread prodcon.c -lpthread 

are sure use pthead_mutex_lock? or typo? anyways should pthread_mutex_lock. same pthread_mutex_unlock.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -