pthread create報出未定義錯誤

2021-10-06 15:13:06 字數 385 閱讀 4242

在c**中包含了通檔案pthread.h,

#include

但還是報錯了沒有定義的錯誤:

undefined reference to 'pthread_create'

undefined reference to 'pthread_join'

問題原因:

pthread 庫不是 linux 系統預設的庫,連線時需要使用靜態庫 libpthread.a,所以在使用pthread_create()建立執行緒,以及呼叫 pthread_atfork()函式建立fork處理程式時,需要鏈結該庫。

問題解決:

在編譯中要加 -lpthread引數

gcc thread_test.c -o thread_test -lpthread

pthread create 函式用法

天開始學習linux下用c開發多執行緒程式,linux系統下的多執行緒遵循posix執行緒介面,稱為pthread。include int pthread create pthread t restrict tidp,const pthread attr t restrict attr,void s...

pthread create函式詳解

pthread create是unix環境建立執行緒函式 include int pthread create pthread t restrict tidp,const pthread attr t restrict attr,void start rtn void void restrict a...

pthread create引數傳遞

說明 本文 多執行緒程式設計之pthread create函式應用,在此基礎上筆者做了些許改動。pthread create函式 函式簡介 pthread create是unix環境建立執行緒函式 標頭檔案 include 函式宣告 int pthread create pthread t rest...