Compile and link with -pthread, not -lpthread.