33

I'm trying to compile a C program but I get the error 'RTLD_NEXT' undeclared. I think this is supposed to be defined in dlfcn.h which the c program includes, but when I looked inside dlfcn.h there is no RTLD_NEXT.

How do I fix this?

neuromancer
  • 53,769
  • 78
  • 166
  • 223
  • You had better tell us exactly what Linux distro and gcc version if you are defining _GNU_SOURCE and not succeeding. – bmargulies Nov 22 '09 at 02:21
  • 4
    @bmargulies: he's using cygwin (see http://stackoverflow.com/questions/1777523/how-to-make-this-c-program-compile/1777566#1777566 ), which does not support `RTLD_NEXT` (see eg http://lists.zerezo.com/cygwin/msg38882.html ) – Christoph Nov 22 '09 at 02:41

4 Answers4

39

The issue here is that RTLD_NEXT is not defined by the posix standard . So the GNU people don't enable it unless you #define _GNU_SOURCE or -D_GNU_SOURCE.

Other relevant pieces of POSIX are dlfcn.h and dlsym.h. Interestingly, the later mentions RTLD_NEXT. Apparently, the GNU people are a bit confused about what is an extension and what is not.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • better link to http://www.opengroup.org/onlinepubs/009695399/basedefs/dlfcn.h.html and http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html#tag_03_112_07 – Christoph Nov 22 '09 at 01:56
10

According to man dlsym it is #define _GNU_SOURCE (just one leading underscore) before the dlfcn.h is included. (RHEL6.1).

eeerahul
  • 1,629
  • 4
  • 27
  • 38
Martin
  • 101
  • 1
  • 2
5

Try #define __GNU_SOURCE as first line in your sources.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
user175104
  • 3,598
  • 2
  • 23
  • 20
3

There must be one underscore. #define _GNU_SOURCE Further, this must be your first preprocessor directive.For example:

#define _GNU_SOURCE  
#include <stdio.h>