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


問題原因:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM