作者wanilly (我恨你!)
看板C_and_CPP
標題Re: [語法] 關於pthread
時間Sat Mar 14 17:58:01 2009
下面是錯誤的訊息
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
1F:→ fuha:-lpthread 03/14 20:44
2F:→ fuha:上面打錯 你第二個參數要 null 03/14 20:48