undefined reference to `pthread_create' collect2: ld returned 1 exit status

Linux下编译多线程程序遇到错误:

undefined reference to `pthread_create'
collect2: ld returned 1 exit status

原因是系统无法找到pthread_create函数。也就是说编译器在link得时候找不到其中的一个使用库的函数。

解决办法如下:

For Linux the correct command is:

gcc -pthread xxx.c

In general, libraries should follow sources and objects on command line, and -lpthread is not an "option", it's a library specification. On a system with only libpthread.a installed,

gcc -lpthread xxx.c//By this, ld will try to link libpthread.so

will fail to link.

posted @ 2015-06-05 00:23  fosmj  阅读(1666)  评论(0)    收藏  举报