博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
_GNU_SOURCE和__USE_GNU的差别
阅读量:4004 次
发布时间:2019-05-24

本文共 2335 字,大约阅读时间需要 7 分钟。

本文转载至:

c-cpp.c:

用gcc编译不过,用g++可以:

$ g++ c-cpp.c
$ gcc c-cpp.c
c-cpp.c: In function ‘main’:
c-cpp.c:12:17: error: ‘REG_R8’ undeclared (first use in this function)
c-cpp.c:12:17: note: each undeclared identifier is reported only once for each function it appears in
其预处理上有差别:
$ gcc siginfo.c -E >gcc.c
$ g++ siginfo.c -E >g++.c

在/usr/include/x86_64-linux-gnu/sys/ucontext.h 文件里,定义了:

经过预处理,gcc.c显示为:

g++.c显示为:

很明显,gcc版本的,没有enum,所有gcc编译不过。

换一下:

看下在gcc下,两者的预处理差别:

/usr/include/features.h 里面,首先会:

然后根据_GNU_SOURCE来定义:

__USE_GNU 不是开放给用户用的,features.h里面会修改,但 _GNU_SOURCE 不会,它才是给用户用的

看features.h里的注释:
These are defined by the user (or the compiler) to specify the desired environment:
_GNU_SOURCE All of the above, plus GNU extensions.

These are defined by this file and are used by the header files to decide what to declare or define:

__USE_GNU Define GNU extensions.

修改方法,在代码最开始,添加:

或者,直接在编译选项里定义。

而gcc和g++的默认定义也有区别,因为g++默认定义了_GNU_SOURCE,所以g++可以编译过而gcc编译不过。

在这里  也搜索到答案,但是之前没有太留意。

I believe you should either have #define _GNU_SOURCE as the first line of your source file, or better put -D_GNU_SOURCE in your CFLAGS (on the command line). Then make sure you include and .

你可能感兴趣的文章
在android上运行native可执行程序
查看>>
Phone双模修改涉及文件列表
查看>>
android UI小知识点
查看>>
Android之TelephonyManager类的方法详解
查看>>
android raw读取超过1M文件的方法
查看>>
ubuntu下SVN服务器安装配置
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>
捕鱼忍者(ninja fishing)之游戏指南+游戏攻略+游戏体验
查看>>
iphone开发基础之objective-c学习
查看>>
iphone开发之SDK研究(待续)
查看>>
计算机网络复习要点
查看>>
Variable property attributes or Modifiers in iOS
查看>>
NSNotificationCenter 用法总结
查看>>
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>
部分笔试算法题整理
查看>>