pthread線程創建出現undefined reference to `pthread_create' collect2: error: ld returned 1 exit status

最近看《Gnu/linux編程》線程這章時,自己便試着寫了一個簡單實例,然後用gcc編譯,結果出現:pthread.c:(.text+0x29): undefined reference to `pthread_create'

collect2: error: ld returned 1 exit status。這時便發揮google的功效,問題得以解決。方法如下:

只需在用gcc編譯時加上-pthread選項即可。(原因是沒有鏈接上pthread庫)


參考:http://stackoverflow.com/questions/4121090/why-do-i-get-undefined-reference-errors-even-when-i-include-the-right-header-f


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