什么是-D_XOPEN_SOURCE做/是什么意思? [英] What does -D_XOPEN_SOURCE do/mean?

查看:891
本文介绍了什么是-D_XOPEN_SOURCE做/是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一些code的GCC没有这个ARG不会编译。我检查了海湾合作委员会手册页,却没有发现这个特定的选项。我没有找到 XOPEN_SOURCE ,但有什么它做一点解释。

I recently encountered some code that gcc would not compile without this arg. I checked the gcc man page, but did not find this specific option. I did find XOPEN_SOURCE, but there was little explanation of what it does.

可有人请详细点吗?我知道 -D_XOPEN_SOURCE 可设置为不同的值,例如 400 600 ,但什么做那些呢?

Can someone please elaborate? I know -D_XOPEN_SOURCE can be set to different values, such 400, 600, but what do those do?

推荐答案

当你做

#define _XOPEN_SOURCE <some number>

cc -D_XOPEN_SOURCE=<some number>

它会告诉你的编译器包含在X / Open和POSIX标准中定义的一些额外的功能定义。

it tells your compiler to include definitions for some extra functions that are defined in the X/Open and POSIX standards.

这会给你存在于最新的UNIX / BSD / Linux系统,但可能在其他系统如Windows不存在一些额外的功能。

This will give you some extra functionality that exists on most recent UNIX/BSD/Linux systems, but probably doesn't exist on other systems such as Windows.

中的数字代表不同版本的标准

The numbers refer to different versions of the standard.

  • 500 - X/Open 5, incorporating POSIX 1995
  • 600 - X/Open 6, incorporating POSIX 2004
  • 700 - X/Open 7, incorporating POSIX 2008

您可以告诉你需要哪一个(如果有的话)通过查看每次调用函数的手册页。

You can tell which one you need (if any) by looking at the man page for each function you call.

例如,的strdup人说:

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       strdup(): _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
       strndup(), strdupa(), strndupa(): _GNU_SOURCE

这意味着你应该把其中的一个:

Which means that you should put one of these:

#define _SVID_SOURCE
#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
#define _XOPEN_SOURCE 600
#define _XOPEN_SOURCE 700

在源文件中做任何的#include ■如果您想使用前顶部的strdup

at the top of your source file before doing any #includes if you want to use strdup.

或者你可以把

#define _GNU_SOURCE

有相反,它使所有的功能,与它可能无法在Solaris,FreeBSD的,Mac OS X中,编译等缺点。

there instead, which enables all functionality, with the downside that it might not compile on Solaris, FreeBSD, Mac OS X, etc.

这是一个好主意,做一个的#include 的#define ,或使用前要检查每一个人页面新的功能,因为有时候他们的行为改变取决于哪些选项和的#define 你得了,例如使用的基本名(3)

It's a good idea to check each man page before doing a #include, #define, or using a new function, because sometimes their behavior changes depending on what options and #defines you have, for example with basename(3).

另请参阅:

  • -std=c99 wtf on Linux
  • glibc feature test macros
  • The Compilation Environment - Open Group Base Specification issue 6 (a.k.a. X/Open 6)
  • POSIX - Wikipedia
  • Single UNIX Specification - Wikipedia

这篇关于什么是-D_XOPEN_SOURCE做/是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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