我试图运行一个例子来处理信号,它无法编译一个未知的标识符。
这是如何加载头:
#define __USE_GNU #include <ucontext.h>
而编译错误(与海湾合作委员会):
$ gcc -o sa_siginfo sa_siginfo.c sa_siginfo.c: In function 'bt_sighandler': sa_siginfo.c:25:28: error: 'REG_RIP' undeclared (first use in this function) uc->uc_mcontext.gregs[REG_RIP]);
GCC信息:
$ gcc --version gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
/usr/include/ucontext.h确实包含/usr/include/sys/ucontext.h其中包含:
#ifdef __x86_64__ [...] #ifdef __USE_GNU /* Number of each register in the `gregset_t' array. */ enum { [...] REG_RIP,
(我的系统是64位)
所以我不明白为什么不find它?
尝试像这样编译你的程序
gcc -D_GNU_SOURCE -o sa_siginfo sa_siginfo.c
这个__USE_GNU
只有在你定义了_GNU_SOURCE
__USE_GNU
被定义,而gcc
在默认情况下不会定义它。