Without seeing the compiler command, I suspect -lpthread is not at end. Libraries need to be placed at end of the compiler command:
gcc main.c -lpthread
However, use -pthread instead of -lpthread, as -pthread may add other settings (like defining the macro _REENTRANT for example).