写字符设备驱动程序时,出现错误: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