Re: [語法] 關於pthread
下面是錯誤的訊息
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
03/14 20:44, 1F
→
03/14 20:48, , 2F
03/14 20:48, 2F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章