So I am getting the error: \"undefined reference to sem_open()\" even though I have include the semaphore.h header. The same thing is happening for all my pthread function
You need link with pthread lib, using -lpthread option.
-lpthread