關於pthread.h - Linux

Gilbert avatar
By Gilbert
at 2009-11-22T15:37

Table of Contents

我寫了一個程式 欲印出下列訊息:
This is Hello thread.
Thread ID:
Argument:100
------------------------------------------------
程式碼如下
------------------------------------------------
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

void *PrintHello(void *arg)
{
printf("This is Hello thread.\n");
printf("Thread ID: %lu\n",pthread_self());
printf("Argument: %d\n",(int) arg);
pthread_exit(NULL);
}



int main()
{
pthread_t thread;
int rc,t = 100;
rc = pthread_create(&thread,NULL,PrintHello,(void *)t);

if(rc){
printf("ERROR; return the code from the pthread_creat() is %d\n",rc);
exit(-1);
}

rc = pthread_join(thread,NULL);
if(rc){
printf("ERROR; return the code from the pthread_join() is %d\n",rc);
exit(-1);
}

return 0;
}

------------------------(分隔線)----------------------------
結果gcc編譯時出現以下訊息:

/tmp/cco6vngs.o: In function `main':
thread_example.c:(.text+0x79): undefined reference to `pthread_create'
thread_example.c:(.text+0xb9): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

這是哪裡出問題 小弟不太懂 有那位大大能回答我的 感激不盡

--
Tags: Linux

All Comments

Genevieve avatar
By Genevieve
at 2009-11-22T21:25
需要link librery,compile時加上-lpthread or -pthread
Ula avatar
By Ula
at 2009-11-23T06:16
a
Anonymous avatar
By Anonymous
at 2009-11-27T12:01
真的可以了耶 謝謝^^

超級新手的苦惱

Todd Johnson avatar
By Todd Johnson
at 2009-11-22T00:43
=== 引言恕刪 === 講一下我的感覺,以及使用、學習 Linux 的經驗。 我仍然不算是and#34;老手and#34;,還有許多東西得學習。 我認為,學習或是使用 Linux 的第一步。 就是「忘記曾經用過 Windows」,要把 Linux 當作另種作業系統。 事實上 Linux 的確是一個從設計想 ...

ifconfig的訊息 想請教一下

Hamiltion avatar
By Hamiltion
at 2009-11-21T23:59
先說過無關的東西... 沒有 Ubuntu 9.0.4 這種東西... Ubuntu 的版本命名比較特別,是西元年加出版月。 它是每年 4 月和 10 月底會出新的版本。 所以你用的版本應該是 9.4 (2009 年 4 月底釋出)。 如果你真的是用 9.0.4... 那... 建議你換個版本... Ubu ...

ifconfig的訊息 想請教一下

Frederica avatar
By Frederica
at 2009-11-21T23:30
我是用 Ctrl + Alt + F8 回到GUI 有時候會變成 F7 才是GUI 但光是連線就已經超出我的修養極限 此問題暫不理... DNS我在/etc/resolv.conf中設定還是不行 後來我想從Gateway下手 發現我沒有 /etc/sysconfig/network 這個東西 連syscon ...

CentOS 4.8 用 yum 升到 5.x ?

Joe avatar
By Joe
at 2009-11-21T23:26
請問一下 手邊一部 CentOS 4.8 想要升到 5.x 但是沒有光碟機~~ 請問 用 yum 可以升嗎??? 要怎麼做呢???? -- ███▌ ███ ▌██▌ █▎▊█  ██ █  █ ▋▌ █▌█▌█▌▌▌▌▌ █  █ █   █  █ ████ █ █ ██ █ ▋▌  ▌▌ ...

ifconfig的訊息 想請教一下

Liam avatar
By Liam
at 2009-11-21T22:06
※ 引述《aquaeelziq (我是男的(真的啦...))》之銘言: : 不好意思再請問一下 如果在文字介面上網路設定成功的話 : 回到視窗介面是不是應該也可以連線上網? 看怎麼回GUI的,重開機嗎? XD 那連線可能就不見了,除非pppoeconf時有設開機啟動 要重新連線,用終端機視窗執行pon (po ...