Linux驱动——fatal error: asm/system.h: No such file or directory 如何解决

写字符设备驱动程序时,出现错误:fatal error: asm/system.h: No such file or directory

错误信息可知,缺少此头文件

原因:

        Linux内核是不断地更新换代,即3.3版本之后内核用switch_to.h替换了曾经的system.h头文件。

解决方法:

        可在终端输入uname -r,查看自己Linux内核版本。如,我的内核版本是4.2.0-27-generic,可知为3.3之后版本,直接使用#include <asm/switch_to.h>替换掉原来的#include <asm/system.h>

        或者写以下下代码即可:

#include <linux/version.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 3, 0)
        #include <asm/switch_to.h>
#else
        #include <asm/system.h>
#endif

        

猜你喜欢

转载自blog.csdn.net/qq_35277038/article/details/80498210