如何开启_GNU_SOURCE宏
在编写网络程序时,会涉及到一些关于BSD系统保留下的结构体和宏定义,关于一切配置在linux系统的/usr/include/features.h文件中,开启项如下:
#ifdef _GNU_SOURCE
# undef _ISOC99_SOURCE
# define _ISOC99_SOURCE 1
# undef _POSIX_SOURCE
# define _POSIX_SOURCE 1
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 199506L
# undef _XOPEN_SOURCE
# define _XOPEN_SOURCE 600
# undef _XOPEN_SOURCE_EXTENDED
# define _XOPEN_SOURCE_EXTENDED 1
# undef _LARGEFILE64_SOURCE
# define _LARGEFILE64_SOURCE 1
# undef _BSD_SOURCE
# define _BSD_SOURCE 1
# undef _SVID_SOURCE
# define _SVID_SOURCE 1
#endif
可以看出只要开启了_GNU_SOURCE的花,大部分的BSD功能可以打开,看看_GNU_SOURCE是否开启有一个测试程序:
#include <iostream>
int main()
{
#ifdef _GNU_SOURCE
std::cout << "gnu/n";
#else
std::cout << "non-gnu/n";
#endif
}
只要gcc -D _GNU_SOURCE test.c -o test.o编译生成的text.o文件,运行一下就知道是否开启了
更多推荐
所有评论(0)