在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)
問題解決。
但懂得內核的朋友能否給我解釋下爲什麼有上面的錯誤?