4

This is my mman.h file included from /usr/include/sys/:

http://pastebin.com/FZpHwKMC

Somehow mmap() seems to be defined (and can be used with flags 0 and read/write protection), but not MAP_ANON or MAP_ANONYMOUS as indicated below:

#include <sys/mman.h>

int a = MAP_ANON; /* compile error */
int b = MAP_ANONYMOUS; /* also compile error */

I'm at a loss of what could be wrong. I'm compiling using this makefile:

http://pastebin.com/R1V2edmf

EDIT: It turns out the MAP_ANONYMOUS macro is defined in /usr/include/bits/mman.h but only if __USE_MISC is defined...

Any help would be terrific!

bombax
  • 1,189
  • 8
  • 26

1 Answers1

6

If you're using GCC, a common reason for this to occur is that you're not using a GNU C standard. Try compiling with, e.g., -std=gnu11, and see if that fixes the problem.

More information about GCC's language standards can be found here.

GCC also provides a very exhaustive list of exactly what extensions they provide here.

Also, as a side note, it's preferrable to use MAP_ANONYMOUS instead of MAP_ANON, as the latter is deprecated (according to man mmap).

CmdrMoozy
  • 3,870
  • 3
  • 19
  • 31
  • Thanks! Will try to compile with this flag, and see if it helps. I've edited my post. – bombax May 22 '14 at 21:40
  • 2
    Yeah, this is it. The ANON options are not portable outside of the gnu compiler suite, so you have to have at least -std=gnu89 at minimum. Interestingly, on my AIX and HPUX boxes, the options are there by default in the IBM and HP compilers.... – JohnH May 22 '14 at 21:42
  • Glad to help. :) I actually had this same problem earlier today. – CmdrMoozy May 22 '14 at 21:44
  • 1
    The mmap() manpage suggests that _GNU_SOURCE is more than enough to solve the problem. – b3h3m0th Feb 13 '16 at 18:25