Replaced -lpthread with -pthread. Do not understand why this works.