Re: [語法] 關於pthread

看板C_and_CPP (C/C++)作者 (我恨你!)時間16年前 (2009/03/14 17:58), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串2/2 (看更多)
下面是錯誤的訊息 gcc -lpthread test.c test.c: In function `main': test.c:16: error: `pthread_attr_default' undeclared(first use in this function) test.c:16: error: (Each undeclared identifier is reported only once test.c:16: error: for each function it appears in.) ※ 引述《wanilly (我恨你!)》之銘言: : 下面為一個簡單的範例 使用pthread : 我在網路上看到的簡單範例 : 但是我在linux下編譯卻無法通過 : 請問一下我是不是遺漏了什麼(編譯上) : 我想程式碼應該不會有錯誤 因為是網路上的範例 : 謝謝 : ============================ : #include <stdio.h> : #include <stdlib.h> : #include <pthread.h> : void print_message_function( void *ptr ); : int main(void) : { : pthread_t thread1, thread2; : char *message1 = "Hello"; : char *message2 = "World"; : pthread_create(&thread1, pthread_attr_default, : (void*)&print_message_function, (void*) message1); : pthread_create(&thread2, pthread_attr_default, : (void*)&print_message_function, (void*) message2); : return 0; : } : void print_message_function( void *ptr ) : { : char *message; : message = (char *) ptr; : printf("%s ", message); : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.217.7

03/14 20:44, , 1F
-lpthread
03/14 20:44, 1F

03/14 20:48, , 2F
上面打錯 你第二個參數要 null
03/14 20:48, 2F
文章代碼(AID): #19kt-gr6 (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
1
4
完整討論串 (本文為第 2 之 2 篇):
1
4
文章代碼(AID): #19kt-gr6 (C_and_CPP)