簡體   English   中英

Simple.c 文件無法編譯 pthreads.h

[英]Simple .c file fails to compile pthreads.h

我是一個長期的 python 愛好者,將腳本移植到 c。 我相信環境中有問題阻止代碼編譯。 其他地方的研究讓我相信它與 posix header 文件有關? 也許有宏? 我在 c 方面的經驗不足,無法弄清楚。

相關片段在這里:

pthread_t id;
thread_create(&id, NULL, refreshqb,NULL);
void *status;
pthread_start(id, (void**)&status);

我收到的錯誤是這樣的。

t.c:91:4: warning: implicit declaration of function 'thread_create' is invalid in C99
      [-Wimplicit-function-declaration]
   thread_create(&id, NULL, refreshqb,NULL);
   ^
t.c:93:4: warning: implicit declaration of function 'pthread_start' is invalid in C99
      [-Wimplicit-function-declaration]
   pthread_start(id, (void**)&status);
   ^
2 warnings generated.
Undefined symbols for architecture x86_64:
  "_pthread_start", referenced from:
      _main in t-0d3a02.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

編譯代碼時必須顯式啟用對 pthreads 的支持。 看起來您使用的是 clang,因此只需在使用 clang 編譯時添加-pthread標志。

請嘗試使用 pthread_create,並包含正確的 posix 庫 header 或“#include <pthread.h>”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM