linux:gcc編譯出“error: ld returned 1 exit status”

運行某書上給的線程創建與結束的例子,在linux下用gcc編譯代碼,出現如下問題

/tmp/cclpFs9V.o: In function `main':
test.cpp:(.text+0x52): undefined reference to `pthread_create'
test.cpp:(.text+0x89): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status

解決方法:

g++ xxx -lpthread

之後再運行程序,成功!

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