(轉)undefined reference to 'pthread_create'問題

undefined reference to 'pthread_create'問題解決

轉者按:怪不得star在書上寫了相關批註。看來,實踐還是很關鍵的。

 

問題:
undefined reference to 'pthread_create'

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

問題解決:
    在編譯中要加 -lpthread參數
    gcc thread.c -o thread -lpthread
    thread.c爲你些的源文件,不要忘了加上頭文件#include<pthread.h>

 

原文:http://blog.chinaunix.net/u3/95416/showart_2102037.html

 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章