undefined reference to 'pthread_create'問題解決

着GUN/Linux編程指南中的一個例子輸入編譯,結果出現如下錯誤:
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'


問題原因:
    pthread 庫不是 Linux 系統默認的庫,連接時需要使用靜態庫 libpthread.a,所以在使用pthread_create()創建線程,以及調用 pthread_atfork()函數建立fork處理程序時,需要鏈接該庫。


問題解決:
    在編譯中要加 -lpthread參數
    gcc thread.c -o thread -lpthread
    thread.c爲你些的源文件,不要忘了加上頭文件#include<pthread.h>
發佈了36 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章