pthread.h 的 undefined reference to `pthread_create'

在編譯中要加 -lpthread或-pthread參數(不一樣版本的gcc可能不同,man gcc能夠查閱對應參數)。編譯

例如:在加了頭文件#include <pthread.h>以後執行 pthread.c文件,須要使用以下命令:thread

    gcc -lpthread -o thread thread.cgcc

gc

    gcc -pthread -o thread thread.c文件

這種狀況相似於<math.h>的使用,需在編譯時加 -m 參數。math

相關文章
相關標籤/搜索