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
_GNU_SOURCE and __USE_GNU
提问by Foo Bah
I want to use CPU_SET
, which is a glibc linux-specific macro that should be defined in sched.h
The manpage clearly states that _GNU_SOURCE
must be defined so that the macro is defined. However, looking at the header, CPU_SET
is defined only if __USE_GNU
is defined (there is an #ifdef
guard). I seem to remember a few years ago that _GNU_SOURCE
was 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_SOURCE
to __USE_GNU
happen (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_GNU
is sufficient?
3) 是否存在较新版本的 glibc 仍在使用的情况_GNU_SOURCE
?或者我可以安全地假设定义__USE_GNU
就足够了?
采纳答案by R.. GitHub STOP HELPING ICE
_GNU_SOURCE
is the only one you should ever define yourself. __USE_GNU
is defined internally through a mechanism in features.h
(which is included by all other glibc headers) when _GNU_SOURCE
is defined, and possibly under other conditions. Defining or undefining __USE_GNU
yourself 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;
}