当前位置: 技术问答>linux和unix
linux内核设计实验——动态模块设计
来源: 互联网 发布时间:2016-12-02
本文导语: 内核信息:Linux student-Lenovo 2.6.35-23-generic-pae #41-Ubuntu SMP Wed Nov 24 10:35:46 UTC 2010 i686 GNU/Linux 下面的程序是实验知道书上的样例,没有问题可言,关键就是我在用 gcc -c file.c -o file.o 时提示没有下面的头文件 ...
内核信息:Linux student-Lenovo 2.6.35-23-generic-pae #41-Ubuntu SMP Wed Nov 24 10:35:46 UTC 2010 i686 GNU/Linux
下面的程序是实验知道书上的样例,没有问题可言,关键就是我在用 gcc -c file.c -o file.o 时提示没有下面的头文件
locate linux/kernel.h 发现前5个头文件都在/usr/src/linux-headers-2.6.35-23-generic-pae/include/目录下
最头疼的是第6个头文件asm/processor.h, locate了一下,输出:
/usr/src/linux-headers-2.6.35-22/arch/alpha/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/arm/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/avr32/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/blackfin/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/cris/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/frv/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/h8300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/ia64/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/m32r/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/m68k/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/microblaze/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/mips/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/mn10300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/parisc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/powerpc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/s390/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/score/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/sh/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/sparc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/x86/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/xtensa/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/alpha/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/arm/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/avr32/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/blackfin/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/cris/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/frv/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/h8300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/ia64/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/m32r/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/m68k/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/microblaze/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/mips/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/mn10300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/parisc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/powerpc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/s390/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/score/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/sh/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/sparc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/x86/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/xtensa/include/asm/processor.h
不知道怎么办了? 这是大三linux 内核设计与分析的实验,有做过的人麻烦指点下,最好不要谈什么升级版本什么的,在实验室升级了下次也不能用。
#include————1
#include ———2
#include —————3
#include ———4
#include ————5
#include ——6
#include
#define MODULE_NAME "Myproc"
#define MYDATA_LEN 16
/*************************************
程序主体
*************************************/
下面的程序是实验知道书上的样例,没有问题可言,关键就是我在用 gcc -c file.c -o file.o 时提示没有下面的头文件
locate linux/kernel.h 发现前5个头文件都在/usr/src/linux-headers-2.6.35-23-generic-pae/include/目录下
最头疼的是第6个头文件asm/processor.h, locate了一下,输出:
/usr/src/linux-headers-2.6.35-22/arch/alpha/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/arm/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/avr32/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/blackfin/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/cris/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/frv/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/h8300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/ia64/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/m32r/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/m68k/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/microblaze/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/mips/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/mn10300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/parisc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/powerpc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/s390/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/score/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/sh/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/sparc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/x86/include/asm/processor.h
/usr/src/linux-headers-2.6.35-22/arch/xtensa/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/alpha/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/arm/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/avr32/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/blackfin/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/cris/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/frv/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/h8300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/ia64/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/m32r/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/m68k/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/microblaze/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/mips/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/mn10300/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/parisc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/powerpc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/s390/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/score/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/sh/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/sparc/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/x86/include/asm/processor.h
/usr/src/linux-headers-2.6.35-23/arch/xtensa/include/asm/processor.h
不知道怎么办了? 这是大三linux 内核设计与分析的实验,有做过的人麻烦指点下,最好不要谈什么升级版本什么的,在实验室升级了下次也不能用。
#include————1
#include ———2
#include —————3
#include ———4
#include ————5
#include ——6
#include
#define MODULE_NAME "Myproc"
#define MYDATA_LEN 16
/*************************************
程序主体
*************************************/
|
支持
|
“gcc -c file.c -o file.o 时提示没有下面的头文件 locate linux/kernel.h”
很显然,你没有给gcc指定头文件的路径: “-I/usr/src/linux-headers-2.6.35-23-generic-pae/include/”,gcc找不到他们。
你编的是内核文件,在2.6.*下这样编译是不行的,你需要看看内核模块编译方面的资料,写个Makefile,你可以看一下:《LinuxDeviceDrivers3》,有中文版的,你看个开头就明白了。
很显然,你没有给gcc指定头文件的路径: “-I/usr/src/linux-headers-2.6.35-23-generic-pae/include/”,gcc找不到他们。
你编的是内核文件,在2.6.*下这样编译是不行的,你需要看看内核模块编译方面的资料,写个Makefile,你可以看一下:《LinuxDeviceDrivers3》,有中文版的,你看个开头就明白了。
|
编译内核模块不恩你个简单的用gcc -c file.c -o file.o
需要按照kbuild的规则来写个Makefile,
楼上说到那个书上有例子,教你怎么编译一个最简单的模块的。
试试这个吧:
需要按照kbuild的规则来写个Makefile,
楼上说到那个书上有例子,教你怎么编译一个最简单的模块的。
试试这个吧:
# builds the example kernel modules;
# then to use one (as root): insmod
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m += file.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif