https://www.cnblogs.com/jiu0821/p/5855827.html
問題原因:
pthread 庫不是 Linux 系統默認的庫,連接時需要使用靜態庫 libpthread.a.
所以在使用pthread_create()創建線程時,需要鏈接該庫。
1. 終端:問題解決:
在編譯中要加 -pthread參數
gcc thread.c -o thread -pthread
2. qt的cmake配置: 可以修改CMakeLists.txt:
Here is the right answer:
ADD_EXECUTABLE(your_executable ${source_files}) TARGET_LINK_LIBRARIES( your_executable pthread )
equivalent to
-pthread