Linux中編譯C C 多執行緒程式

2021-07-22 09:43:29 字數 552 閱讀 5070

編譯執行多執行緒程式

編譯上述多執行緒程式,必須使用 -lpthread編譯選項,因為pthread庫不是linux預設鏈結庫,鏈結時必須指定使用libpthread.a庫(ubuntu11.10這些庫在/usr/lib/i386-linux-gnu路徑下),在編譯選項中需新增-lpthread引數,示例如:

c編譯選項:

gcc test.c -o test-lpthread

c++編譯選項:

g++ ctest.cpp test.cpp -o test -lpthread

如果是寫到makefile中,可以找到類似targ_options=這樣的位置新增-lpthread。

但是往往還是會報告pthread_create未宣告問題,說明編譯器仍未找到libpthead.a的位置,這時可手動在編譯命令列中新增:-l./usr/lib/i386-linux-gnu 選項(這裡的路徑是libthread.a路徑,不同系統、機子可能有所不同!!)

C C 多執行緒

前幾天簡單對c和c 中的建立多執行緒的函式進行了測試,這篇隨筆就簡單介紹一下建立執行緒的相關函式。c中三個建立執行緒函式 pthread create beginthread createthread 三個關閉執行緒函式 pthread exit endthread exitthread 標頭檔案分...

Linux下C C 程式編譯

在編譯之前我們需要在系統裡安裝g gcc,它們就是linux下的c c的編譯器。如下 sudo apt get install build essential sudo apt get install gcc sudo apt get install g 好,現在我們在文字編輯器裡寫乙個c的簡單的程...

linux編譯執行C C 程式

在linux系統下編譯執行c c 程式。編譯c程式使用gcc,編譯c 程式使用g ubuntu14.04預設安裝了gcc,但是沒有安裝g 1.首先確定已經安裝gcc g 使用whereis gcc或者whereis g 檢視是否安裝gcc g 命令如下 liu liu whereis g 如果安裝,...