當(dāng)前位置:
首頁(yè) >
undefined reference to 'pthread_create'问题解决
發(fā)布時(shí)間:2025/7/14
40
豆豆
生活随笔
收集整理的這篇文章主要介紹了
undefined reference to 'pthread_create'问题解决
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
由于是Linux新手,所以現(xiàn)在才開(kāi)始接觸線程編程,照著GUN/Linux編程指南中的一個(gè)例子輸入編譯,結(jié)果出現(xiàn)如下錯(cuò)誤:
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
問(wèn)題原因:
????pthread 庫(kù)不是 Linux 系統(tǒng)默認(rèn)的庫(kù),連接時(shí)需要使用靜態(tài)庫(kù) libpthread.a,所以在使用pthread_create()創(chuàng)建線程,以及調(diào)用 pthread_atfork()函數(shù)建立fork處理程序時(shí),需要鏈接該庫(kù)。
問(wèn)題解決:
??? 在編譯中要加 -lpthread參數(shù)
??? gcc thread.c -o thread -lpthread
??? thread.c為你些的源文件,不要忘了加上頭文件#include<pthread.h>
轉(zhuǎn)載于:https://blog.51cto.com/yuzwei/1650513
總結(jié)
以上是生活随笔為你收集整理的undefined reference to 'pthread_create'问题解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring Security 决策器前
- 下一篇: Lexus Extroic OpenCa