歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 一步一步學Linux C:undefined reference to ‘pthread_create問題解決

一步一步學Linux C:undefined reference to ‘pthread_create問題解決

日期:2017/3/1 10:26:06   编辑: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>

Copyright © Linux教程網 All Rights Reserved