c - linux内核编程找不到头文件
ringa_lee
ringa_lee 2017-04-17 13:53:01
[Linux讨论组]

学校的操作系统课程设计, Ubuntu14.04升级新内核并从新内核启动(4.2.6stable)
后来要求编写一个字符设备驱动, 代码里面

#include
#include
. . . 

结果make的时候提示找不到这些头, 我的makefile里面定义的KDIR是/lib/include/4.2.6/build

驱动代码和makefile都是参照网上的例程的, 以前没有内核开发经验

我自己尝试find types.h头, 后来发现它的上一级目录并不是sys, 有人能详细解说一下么
包括-generic源码里面也没有这样的目录结构

编译完新内核相应的内核树不是也已经建立好了么, 为什么目录结构不一样呢

我的makefile(参照《Linux设备驱动》里面的)

# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
    obj-m := char_dev.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
    #INCLUDE ?= /usr/src/linux-4.2.6/include/linux
    KERNELDIR ?= /lib/modules/3.13.0-24-generic/build
    #/usr/include/x86_64-linux-gnu/
    #/usr/src/linux-4.2.6/include/linux
    PWD := $(shell pwd)
default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

包含的几个头如下:

#include 
#include 
#include 
#include 
#include 


#include 
#include 
#include 
#include 
#include 
#include 
#include 
ringa_lee
ringa_lee

ringa_lee

全部回复(2)
天蓬老师

楼主需要的头文件地址在 /usr/include/sys/
如果是驱动需要的头文件 /usr/src/linux-headers-xxxxx/include/linux/ (xxxx是你的Kernel版本号)

PHP中文网

楼主是否知道头文件的目录,简单一点可以直接在编译的时候指定搜索目录 -I

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号