gcc -lpthread not working
10,336
Try:
gcc -pthread
instead of -lpthread. The difference is significant, I believe. The latter is linking against libpthread, the former is linking against libpthread and a bunch of other things, too!
sem_wait is part of librt, so you could just as well use gcc -lrt, but -pthread does this for you (and everything else as well!).
Author by
Geo Paul
Updated on June 18, 2022Comments
-
Geo Paul 6 months
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.cThe program works fine on other ubuntu installations.
-
DanZimm about 11 yearscan you try compiling something else with pthread calls? -
Kerrek SB about 11 yearsThe linking order matters. Libraries have to come at the end only.
-