无论MAP_ANON和MAP_ANONYMOUS未声明在C SYS / MMAP [英] Both MAP_ANON and MAP_ANONYMOUS undeclared for sys/mmap in C

查看:1250
本文介绍了无论MAP_ANON和MAP_ANONYMOUS未声明在C SYS / MMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从的/ usr / include / sys中/ 包括我的 mman.h 文件:

http://pastebin.com/FZpHwKMC

不知怎的的mmap()似乎被定义(可与标志0被使用和读/写保护),而不是 MAP_ANON MAP_ANONYMOUS 如下所示:

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 */

我在什么可能是错误的亏损。我用这个makefile编译:

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

http://pastebin.com/R1V2edmf

编辑:原来, MAP_ANONYMOUS 宏在 /usr/include/bits/mman.h 定义但如果 __ USE_MISC 定义...

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

任何帮助就太棒了!

推荐答案

如果你使用GCC,为此发生常见的原因是,你不使用GNU C标准。试着用编译,例如 -std = gnu11 ,看看是否能解决问题。

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.

有关GCC的语言标准的详细信息,可以发现 rel=\"nofollow\">。

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

GCC还提供了他们提供的正是扩展的非常详尽的列表的这里

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

此外,作为一个侧面说明,它是preferrable使用 MAP_ANONYMOUS 而不是 MAP_ANON ,作为后者是德precated(据男人MMAP )。

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).

这篇关于无论MAP_ANON和MAP_ANONYMOUS未声明在C SYS / MMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆