_XPG4_2 和其他定义如何在 Solaris 上工作?
在Solaris上,为了获取struct msghdr中的msg_control字段并拥有IPV6_TCLASS,我似乎需要定义_XPG4_2和__EXTENSIONS__。
如果我在包含任何内容之前将它们定义为 1 ,这似乎是可行的:
#if defined (__SVR4) && defined (__sun)
# define _XPG4_2 1
# define __EXTENSIONS__ 1
#endif
- 我应该这样做吗?
- 我是否需要在所有源文件中定义它们,否则可能会发生不好的事情?
- 某处有这些东西的列表吗?
这与
On Solaris, in order to get the msg_control field in struct msghdr and have IPV6_TCLASS I seem to need to define _XPG4_2 and __EXTENSIONS__.
It seems to work if I just define these to 1 before including anything:
#if defined (__SVR4) && defined (__sun)
# define _XPG4_2 1
# define __EXTENSIONS__ 1
#endif
- Should I do it this way?
- Do I need to define them in all source files, or bad things may happen?
- Is there a list of these things somewhere?
This is related to this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
man -k XPG4
显示有一个standards(5)
手册页,其中列出了各种标准的功能测试宏和库链接信息,包括以下内容:通过
/usr/include
查找_XOPEN_SOURCE
会在/usr/include/sys/feature_tests.h
中显示更多信息:因此,自己定义
_XPG4_2
并不是这样做的方法。如果任何结构定义依赖于这些宏,那么您最好在所有翻译单元中定义它们。 最简单的方法是在编译器命令行上指定它们:
如果您使用
make
,则应该能够通过添加-D
参数来完成此操作到CFLAGS
变量:man -k XPG4
reveals that there is astandards(5)
man page, which lists the feature test macros and library linking info for various standards, including the following:Grepping through
/usr/include
for_XOPEN_SOURCE
turns more information in/usr/include/sys/feature_tests.h
:So defining
_XPG4_2
yourself is not the way to do it.If any structure definitions depend on these macros, you would definitely be better off defining them in all translation units. The easiest way to do that is to specify them on the compiler command line:
If you're using
make
, you should be able to do this by adding the-D
parameters to theCFLAGS
variable: