2012-06-15 76 views
4

Android是否支持pthreads? 为什么当我使用-pthread选项,我看到的链接错误:Android支持线程吗?

的i686,Android系统的Linux /斌/劳工处:找不到-lpthread

#include <pthread.h> 
#include <cxxabi.h> 
extern "C" int printf (const char *, ...); 
int main() 
{ 
    try 
    { 
     pthread_exit (0); 
    } 
    catch (abi::__forced_unwind &) 
    { 
     printf ("caught forced unwind\n"); 
     throw; 
    } 
    catch (...) 
    { 
     printf ("caught ...\n"); 
     return 1; 
    } 
} 
+0

你需要使用-lpthread吗?如果仅仅包含“pthread.h? –

回答

7

至于我可以在文档中看到你不需要使用“-pthread”。结帐以下操作:NDK官方文档
http://mobilepearls.com/labs/native-android-api/#pthreads

信息国家(Android的NDK-R8 \文档\ SYSTEM \ libc中\ OVERVIEW.html):

PThread implementation:
Bionic's C library comes with its own pthread implementation bundled in. This is different from other historical C libraries which: - place it in an external library (-lpthread) - play linker tricks with weak symbols at dynamic link time

所以请记住,包括仿生直接pthread,而不是你习惯的标准方式(用-lpthread)。

+0

”我是否可以信任此链接?因为它不是developer.android.com或它们的谷歌组合... – Arseniy

+0

也请查看这一个:https://groups.google。 com/d/topic/android-platform/Cq05PaLaZbE /讨论。一般来说,仿生包括很多pthread函数,但不是全部(例如pthread_barrier_wait()缺失)。 – gfour