背景:g++ test.cpp -o test
报错:undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
分析:pthread不是linux下的默认的库。在链接的时候,无法找到pthread库中函数的入口地址,所以链接会失败。提示:clang: error: linker command failed with exit code 1
解决:gcc编译时,加 ***-lpthread***参数,声明需要连接线程库,才能调用pthread.h中声明的函数。
g++ test.cpp -o test -lpthread
成功编译。



