当我这样做时
ls /usr/src/linux-headers-4.10.0-38-generic/include/linux/sched
我得到以下结果:
deadline.h jobctl.h prio.h rt.h sysctl.h task.h
当我查看时,明显缺少一些文件https://github.com/torvalds/linux/tree/master/include/linux/sched
现在在我的项目中我想使用
signal.h
文件,但它告诉我 fatal error: linux/sched/signal.h: No such file or directory
我做错了什么?
在 4.11 内核中,
<linux/signal.h>
中的一些定义已移至 <linux/sched/signal.h>
,因此,如果您需要使用已移动的定义,则需要根据内核版本有条件地包含其中之一:
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
#include <linux/signal.h>
#else
#include <linux/sched/signal.h>
#endif
请注意,
<linux/sched/signal.h>
包含#include <linux/signal.h>
,因此以下序列将执行相同的操作,但由于无条件包含<linux/signal.h>
,编译速度可能会稍慢:
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
#include <linux/sched/signal.h>
#endif
#include <linux/signal.h>
某些代码只需要移动后留在
<linux/signal.h>
中的定义,在这种情况下,以下内容就足够了,并且与包含 <linux/sched/signal.h>
相比,可以减少编译时间:
#include <linux/signal.h>