運行某書上給的線程創建與結束的例子,在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
之後再運行程序,成功!