undefined reference to 'pthread_create'问题解决
生活随笔
收集整理的這篇文章主要介紹了
undefined reference to 'pthread_create'问题解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
由于是Linux新手,所以現在才開始接觸線程編程,照著GUN/Linux編程指南中的一個例子輸入編譯,結果出現如下錯誤:
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
問題原因:
????pthread 庫不是 Linux 系統默認的庫,連接時需要使用靜態庫 libpthread.a,所以在使用pthread_create()創建線程,以及調用 pthread_atfork()函數建立fork處理程序時,需要鏈接該庫。
問題解決:
??? 在編譯中要加 -lpthread參數
??? gcc thread.c -o thread -lpthread
??? thread.c為你些的源文件,不要忘了加上頭文件#include<pthread.h>
轉載于:https://blog.51cto.com/yuzwei/1650513
總結
以上是生活随笔為你收集整理的undefined reference to 'pthread_create'问题解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Security 决策器前
- 下一篇: Lexus Extroic OpenCa