1. 程式人生 > >thread_join.c:(.text+0x6f): undefined reference to `pthread_create' 問題的解決

thread_join.c:(.text+0x6f): undefined reference to `pthread_create' 問題的解決

今天在測試一個執行緒例子時,結果出現如下錯誤

[[email protected] fzf]# gcc thread_join.c -o thread_join
/tmp/cc1HozRv.o: In function `main':
thread_join.c:(.text+0x6f): undefined reference to `pthread_create'
thread_join.c:(.text+0x91): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

問題原因:

pthread 庫不是 Linux 系統預設的庫,連線時需要使用靜態庫 libpthread.a。

所以在使用pthread_create()建立執行緒,pthread_join()執行緒等待,以及呼叫 pthread_atfork()函式建立fork處理程式時,需要連結該庫。

問題解決如下:
在編譯中要加 -lpthread引數

[[email protected] fzf]# gcc thread_join.c -o thread_join -lpthread

相關推薦

thread_join.c:(.text+0x6f): undefined reference to `pthread_create' 問題的解決

今天在測試一個執行緒例子時,結果出現如下錯誤 [[email protected] fzf]# gcc thread_join.c -o thread_join /tmp/cc1HozRv.o: In function `main': thread_join.

Linux程式設計時使用gcc編譯.c出現以下問題,pthread.c:(.text+0x29): undefined reference to `pthread_create'collect2: err

Linux程式設計時使用gcc編譯.c出現以下問題 client.c:(.text+0x13e): undefined reference to `pthread_create' collect2: ld 返回 1   解決方法如下: 只需在用gcc編譯時加上-pthread選項即

關於移植jSON編譯時報錯sbrkr.c:(.text+0xc): undefined reference to `_sbrk'處理

最近有個專案需要用到jSON函式,在移植了jSON後編譯報錯如下:sbrkr.c:(.text+0xc): undefined reference to `_sbrk'。 通過百度查詢知道原來是GCC編譯器不支援malloc、free、memcpy、strlen等函式導致的,正常在嵌入式系統

gcc xx.c:(.text+0x11): undefined reference to `sqrt'

gcc prime.c -o prime報錯 undefined reference to `sqrt’ 由於程式碼中使用了math庫中的sqrt方法, 所以要這樣寫 gcc prime

ubuntu 12.04 codeblocks undefined reference topthread_create'解決方法

settings---》compiler and bug settings --》link settings 在左邊新增libpthread.a  ,右邊新增 -lpthread即可。 ubuntu libpthread.a 的路徑為 /usr/lib/x86_64-lin

c/c++中出現“undefined reference to”的解決

undefined reference to”的意思是,該函式未定義。 如果使用的是gcc,有以下檢查方案: 如果提示未定義的函式是某個庫的函式。檢查庫時候已經安裝,並在編譯命令中採用-l和-L引數匯入庫。 如果提示未定義的函式是程式中的函式。檢查是否在標頭檔案中宣告

ffmpeg:libavformat/http.c:1435: error: undefined reference to 'inflateEnd'

安卓動態庫編譯過程中遇到了一個ffmpeg相關的報錯,具體資訊如下: libavformat/http.c:1435: error: undefined reference to 'inflateEnd' libavformat/http.c:626: error: undefined re

ffmpeg:libavfilter/vf_elbg.c:169: error: undefined reference to 'avpriv_init_elbg'

ffmpeg編譯過程中遇到的一個報錯,具體資訊如下: -e [info] [*] link ffmpeg -------------------- libavfilter/vf_elbg.c:169: error: undefined reference to 'avpriv_init_el

C++編譯提示“undefined reference to...”

編寫的一個簡單C++時鐘Clock類,放入了標頭檔案中,主函式在呼叫標頭檔案進行編譯時出現上述錯誤,具體程式碼如下: clock.h: #include <iostream> using namespace std; class Clock { private:

Linux Ubuntu執行執行緒程式出現undefined reference topthread_create’和undefined reference to ‘pthread_join’錯誤。

Linux Ubuntu執行執行緒程式出現undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’錯誤。 編寫好執行緒程式碼,進行編譯 gcc xiancheng.c -o xiancheng 出

linux下生產者與消費者問題程式碼,以及編譯c程式碼時error:undefined reference to sem_wait 解決方法之一

//本文的詳細講解內容請大家下載word文件:http://download.csdn.net/detail/chenqiai0/4611801 #include <stdio.h> #include <pthread.h>//執行緒 #includ

Linux 編譯報錯 -- undefined reference to 問題解決方法 (具體'pthread_create'和opencv看文章最後兩條)

最近在Linux下程式設計發現一個詭異的現象,就是在連結一個靜態庫的時候總是報錯,類似下面這樣的錯誤: (.text+0x13): undefined reference to `func'     關於undefined reference這樣的問題,大家其實經常會遇到

解決undefined reference to `pthread_create'的方法

        工作任務需要,寫了一個小的程式模組來通過uart與下位機進行通訊獲取資料,於是想到線上程中監聽uart字元裝置檔案描述符並處理下位機傳過來的資料。在單獨編譯這個小模組的測試程式時,程式

Linux 編譯報錯 undefined reference to `pthread_create'

在編譯Linux下多執行緒程式的時候出現錯誤資訊, 寫好程式碼,進行編譯時,出現如下錯誤提示資訊:  thread.c:(.text+0xae): undefined reference to `pthread_create' thread.c:(.

gcc編譯執行緒程式需帶-lpthread選項(否則出錯:undefined reference to `pthread_create')

程式中兩處使用了pthread_create函式,包含了標頭檔案#include <pthread.h>。 gcc xxx.c -o xxx 編譯時出現以下錯誤: 分析: 用gcc編譯使用了POSIX thread的程式時通常需要加額外的選項,以連結到庫。 此

Linux C/C++ 開發遇到 undefined reference to xxx

環境 CentOS 7.3 CodeBlocks 16.01 gcc 4.9.4 wxGTK 3.0.2 非常簡單的應用。例如: test.h #ifndef TEST_H_INCLUDED #define TEST_H_INCLUDED void test(); #end

ubuntu 下沒有pthread庫以及報undefined reference to 'pthread_create'的解決方法

最近在Ubuntu下編譯一個程式,需要使用多執行緒庫pthread,但是編譯時總是提示“undefined reference to 'pthread_create'”的錯誤,如下圖所示: 要解決這

test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'

defined mpi x11 -c nal pil enc lib issue opencv報錯: test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int

undefined reference to `pthread_create'的錯誤。

晚上編譯一個工程,TMD編譯時總是報thread.o: In function `create_thread': thread.c:(.text+0x1ef): undefined reference to `pthread_create' collect2: ld ret

Linux 編譯報錯 -- undefined reference to 問題解決方法 (具體'pthread_create'和opencv看文章最後兩條)

最近在Linux下程式設計發現一個詭異的現象,就是在連結一個靜態庫的時候總是報錯,類似下面這樣的錯誤: (.text+0x13): undefined reference to `func'     關於undefined reference這樣的問題,大家其實經常會遇