还在苦苦敲代码开发APP?你out啦! 试试积木搭建APP吧~

conflicting types for 'dev_t'的原因

来源:清泛原创     2015-07-24 10:26:17    人气:     我有话说( 0 人参与)

在Linux下编译程序有时会遇到conflicting types for dev_t ,这貌似是一个Linux历史遗留问题,需要调整include头文件的顺序。

Linux下编译程序有时会遇到这种问题,这貌似是一个Linux历史遗留问题:
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here
/usr/include/sys/types.h:67: error: conflicting types for ‘gid_t’
/usr/include/linux/types.h:27: error: previous declaration of ‘gid_t’ was here
/usr/include/sys/types.h:72: error: conflicting types for ‘mode_t’
/usr/include/linux/types.h:15: error: previous declaration of ‘mode_t’ was here
/usr/include/sys/types.h:77: error: conflicting types for ‘nlink_t’
/usr/include/linux/types.h:16: error: previous declaration of ‘nlink_t’ was here
/usr/include/sys/types.h:82: error: conflicting types for ‘uid_t’
/usr/include/linux/types.h:26: error: previous declaration of ‘uid_t’ was here

开始以为是GCC的版本问题,升级了版本也不好使,后来发现!进入编译出错的文件xxx.cpp:

把所有#include <sys/xxx.h>都提到最前面,把#include <linux/xxx.h>的包含放在其后,就可以编译通过了,之所以出现面的问题是存在循环引用所致。如:

#include <linux/apm_bios.h>

#include <sys/types.h>

变成

#include <sys/types.h>

#include <linux/apm_bios.h>

Linux 遗留问题

注:本文为本站或本站会员原创优质内容,版权属于原作者及清泛网所有,
欢迎转载,转载时须注明版权并添加来源链接,谢谢合作! (编辑:admin)
分享到: