conflicting types for 'dev_t'的原因

清泛原创
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 遗留问题

分享到:
评论加载中,请稍后...
创APP如搭积木 - 创意无限,梦想即时!
回到顶部