I have ubuntu 11 installed in my system. I have a c program that uses the pthread library.
I get the error Undefined reference to sem_wait() even if I have compiled with the flag -lpthread.
for example:
gcc -lpthread prog.c
The program works fine on other ubuntu installations.
Try:
instead of
-lpthread. The difference is significant, I believe. The latter is linking againstlibpthread, the former is linking against libpthread and a bunch of other things, too!sem_waitis part of librt, so you could just as well usegcc -lrt, but-pthreaddoes this for you (and everything else as well!).