[英]while compiling thread program on linux machine it gives “undefined reference ” error
嗨,我已經在線程中編寫了一個簡單的程序來創建10個線程並正常執行它們,但是當我在linux機器上編譯代碼時,它給出了以下錯誤。. * / tmp / cc4swqyK.o:在main': threadcreate1.c:(.text+0x40): undefined reference to
函數中main': threadcreate1.c:(.text+0x40): undefined reference to
pthread_create的main': threadcreate1.c:(.text+0x40): undefined reference to
threadcreate1.c :(。text + 0x78):對pthread_join的未定義引用collect2:ld返回1退出狀態*
您是否將其編譯為“ gcc -lpthread fileName.c”
您將必須包含頭文件pthread.h
#include <pthread.h>
並且在編譯時,使用gcc的-l
選項指定要鏈接的庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.