Gcc -lpthread not working

I have ubuntu 11 installed on my system. I have a c program that uses the pthread library. I get an Undefined reference to sem_wait() error even if I compiled with the -lpthread flag.

eg:

 gcc -lpthread prog.c 

The program works fine on other ubuntu installations.

+6
source share
1 answer

Try:

 gcc -pthread 

instead of -lpthread . Of course, the difference is significant. The latter is linked to libpthread , the former is also linked to libpthread and a bunch of other things!

sem_wait is part of librt, so you can use gcc -lrt , but -pthread does this for you (and everything else!).

+12
source

Source: https://habr.com/ru/post/902358/


All Articles