3

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 ?

Simon
  • 2,067
  • 2
  • 17
  • 30
  • 1
    possible duplicate of [How to resolve REG\_EIP undeclared (First use in this function ) error on Linux 32 bit machine?](http://stackoverflow.com/questions/5679267/how-to-resolve-reg-eip-undeclared-first-use-in-this-function-error-on-linux-3) – MBlanc Mar 02 '14 at 18:46
  • Nope I already checked that one – Simon Mar 02 '14 at 19:10
  • Try only doing the preprocessor step of compilation (by giving the right command line switch) and check the output for clues. – hyde Mar 02 '14 at 19:17
  • Also adding the failing compile command, as well as compiler version, to the question might help getting an answer. – hyde Mar 02 '14 at 19:19
  • I didn't include that because it is fairly standard, but I just added these. – Simon Mar 02 '14 at 19:28
  • You could try adding [`-std=gnu99`](http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html) (default is `gnu90`). Also check that `CFLAGS` environment variable is not set with some unexpected flags. – hyde Mar 04 '14 at 07:10

1 Answers1

2

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.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47