linux 線程操作問題undefined reference to 'pthread_create'的解決辦法(cmake)

原文鏈接:https://www.cnblogs.com/jiu0821/p/5855827.html

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