Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting undefined reference to pthread_mutexattr_settype?

I am trying to compile and link a sample file from the Novell LDAP C SDK but the link is failing due to 3 unresolved symbols in the pthread library. I am using gcc 4.8.1 on Ubuntu 13.10 (Saucy). I have properly included the pthread library as the last library on the command line, but these particular symbols are still not being resolved.

$ gcc -Wl,-trace-symbol=pthread_mutexattr_settype -Wl,-trace-symbol=pthread_mutexattr_init   -Wl,-trace-symbol=pthread_mutex_trylock  -o search search.o -L../lib -lldapsdk -lpthread

../lib/libldapsdk.so: reference to pthread_mutexattr_settype<br>
../lib/libldapsdk.so: reference to pthread_mutexattr_init<br>
../lib/libldapsdk.so: reference to pthread_mutex_trylock<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_settype<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_init<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutex_trylock<br>
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_settype<br>
../lib/libldapsdk.so: undefined reference to pthread_mutex_trylock<br>
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_init<br>
collect2: error: ld returned 1 exit status

$ readelf --all  /lib/i386-linux-gnu/libpthread.so.0|grep pthread_mutexattr_settype<br>
   114: 00009d90    36 FUNC    GLOBAL DEFAULT   13 pthread_mutexattr_settype@@GLIBC_2.1<br>
   493: 00009d90    36 FUNC    GLOBAL DEFAULT   13 pthread_mutexattr_settype
like image 687
Bob Avatar asked Mar 04 '14 18:03

Bob


1 Answers

Just writing up the comment as an answer as it proved to be helpful based on other users' feedback.


Please pass -pthread to the compiler (without the -l). See also gcc - significance of -pthread flag when compiling.

like image 81
Ali Avatar answered Sep 20 '22 05:09

Ali