sem_open() error: "undefined reference to sem_open()" on linux (Ubuntu 10.10) sem_open() error: "undefined reference to sem_open()" on linux (Ubuntu 10.10) linux linux

sem_open() error: "undefined reference to sem_open()" on linux (Ubuntu 10.10)


You need link with pthread lib, using -lpthread option.


Including the header does not tell ld about the library. You need to add -lrt to your compilation command line. For threading, you need either -lpthread or -pthread, depending on your platform.

The library is not the header. The header is not the library. This is an important distinction. See What's the difference between a header file and a library?


The working option in Ubuntu is -lpthread. But if you work on suse or other systems the correct option is -lrt. Also the book Linux Programmin Interface mentions -lrt as the correct option.