關於調用函數gettid的錯誤提示

     在OpenSuse 64 v12.3上調用gettid函數(已經加上頭文件sys/types.h),但是gcc -Werror給出如下錯誤提示:

     error: implicit declaration of function 'gettid' [-Werror=implicit-function-declaration]

     而man 2 gettid結果如下:

     NAME
       gettid - get thread identification
    SYNOPSIS
       #include <sys/types.h>
       pid_t gettid(void);   

     我也調用了上面的頭文件,解決不了任何問題,在stackoverflow上看到一個程序使用以下頭文件:

     #include <unistd.h>
     #include <sys/syscall.h>
     #define gettid() syscall(__NR_gettid)

     問題解決。

     但懂得內核的朋友能否給我解釋下爲什麼有上面的錯誤?

      

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章