Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifier not loaded in c

Tags:

c

linux

gcc

I am trying to run a example on handling signals, and it fails compiling on a unfound identifier.

Here is how the header is loaded :

#define __USE_GNU
#include <ucontext.h>

And the error when compiling (with gcc):

$ 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 info:

$ gcc --version
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1

/usr/include/ucontext.h does include /usr/include/sys/ucontext.h which has:

#ifdef __x86_64__
[...]
#ifdef __USE_GNU
/* Number of each register in the `gregset_t' array.  */
enum
{
  [...]
  REG_RIP,

(My system is 64 bits)

So I don't understand why it doesn't find it ?

like image 551
Simon Avatar asked Mar 26 '26 06:03

Simon


1 Answers

Try compiling your program like this

gcc -D_GNU_SOURCE -o sa_siginfo sa_siginfo.c

That __USE_GNU is defined only if you defined _GNU_SOURCE, and gcc will not define it by default.

like image 118
Lee Duhem Avatar answered Mar 27 '26 21:03

Lee Duhem