Linux _GNU_SOURCE 和 __USE_GNU

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7296963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:01:40  来源:igfitidea点击:

_GNU_SOURCE and __USE_GNU

c++clinuxgnuglibc

提问by Foo Bah

I want to use CPU_SET, which is a glibc linux-specific macro that should be defined in sched.hThe manpage clearly states that _GNU_SOURCEmust be defined so that the macro is defined. However, looking at the header, CPU_SETis defined only if __USE_GNUis defined (there is an #ifdefguard). I seem to remember a few years ago that _GNU_SOURCEwas needed.

我想使用CPU_SET,这是一个 glibc linux 特定的宏,应该在sched.h联机帮助页中明确指出_GNU_SOURCE必须定义,以便定义宏。但是,查看标题,CPU_SET仅在定义时才__USE_GNU定义(有#ifdef保护)。我好像记得几年前那_GNU_SOURCE是需要的。

Questions:

问题:

1) Clearly the manpage is off. How do I notify the maintainer that the manpage is incorrect?

1) 显然,联机帮助页已关闭。如何通知维护人员联机帮助页不正确?

2) When did the transition from _GNU_SOURCEto __USE_GNUhappen (either in terms of version or time)

2)什么时候从_GNU_SOURCE__USE_GNU发生的转变(无论是版本还是时间)

3) Are there circumstances where newer versions of glibc still use _GNU_SOURCE? Or can I safely assume that defining __USE_GNUis sufficient?

3) 是否存在较新版本的 glibc 仍在使用的情况_GNU_SOURCE?或者我可以安全地假设定义__USE_GNU就足够了?

采纳答案by R.. GitHub STOP HELPING ICE

_GNU_SOURCEis the only one you should ever define yourself. __USE_GNUis defined internally through a mechanism in features.h(which is included by all other glibc headers) when _GNU_SOURCEis defined, and possibly under other conditions. Defining or undefining __USE_GNUyourself will badly break the glibc headers.

_GNU_SOURCE是您唯一应该定义自己的人。__USE_GNU在定义features.h_GNU_SOURCE(可能在其他条件下)通过 in (所有其他 glibc 头文件中包含的机制)在内部定义。定义或取消定义__USE_GNU自己会严重破坏 glibc 头文件。

回答by Giuseppe Scrivano

you have to define_GNU_SOURCE before anything else. This snippet works here:

你必须先定义_GNU_SOURCE。这个片段在这里工作:

#define _GNU_SOURCE
#include <sched.h>


int main()
{
    cpu_set_t set;
    CPU_SET(0, &set);
    return 0;
}