免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3507 | 回复: 12
打印 上一主题 下一主题

内核编程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-23 16:43 |只看该作者 |倒序浏览
我在刚编译好的新内核下运行最简单的hello world!都报错一大堆,我用的是2.6.28的内核版本,已经把asm,linux等头文件copy到/usr/include下来,怎么还不行亚,我在原来的 25内核版本下,运行
make headers_install 仍然没有modules.h的头文件,没办法只好新编译内核了,可是还是报错一大堆。
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX  -c hello.c
In file included from /usr/include/linux/prefetch.h:14,
                 from /usr/include/linux/list.h:6,
                 from /usr/include/linux/module.h:9,
                 from hello.c:2:
/usr/include/asm/processor.h:113: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/usr/include/asm/processor.h:113: error: requested alignment is not a constant
/usr/include/asm/processor.h: In function ‘load_cr3’:
/usr/include/asm/processor.h:186: error: ‘CONFIG_PAGE_OFFSETUL’ undeclared (first use in this function)
/usr/include/asm/processor.h:186: error: (Each undeclared identifier is reported only once
/usr/include/asm/processor.h:186: error: for each function it appears in.)
/usr/include/asm/processor.h: At top level:
/usr/include/asm/processor.h:235: error: requested alignment is not a constant
/usr/include/asm/processor.h:272: error: requested alignment is not a constant
In file included from /usr/include/linux/elf.h:7,
                 from /usr/include/linux/module.h:14,
                 from hello.c:2:
/usr/include/asm/elf.h: In function ‘elf_common_init’:
/usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r8’
/usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r9’
/usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r10’
/usr/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r11’
/usr/include/asm/elf.h:168: error: ‘struct pt_regs’ has no member named ‘r12’
/usr/include/asm/elf.h:168: error: ‘struct pt_regs’ has no member named ‘r13’
/usr/include/asm/elf.h:168: error: ‘struct pt_regs’ has no member named ‘r14’
/usr/include/asm/elf.h:168: error: ‘struct pt_regs’ has no member named ‘r15’
In file included from /usr/include/linux/module.h:22,
                 from hello.c:2:
/usr/include/asm/module.h:68:2: error: #error unknown processor family
hello.c: In function ‘init_module’:
hello.c:10: warning: implicit declaration of function ‘prink’
make: *** [hello.o] Error 1

这是怎么回事亚!

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2009-03-23 16:49 |只看该作者
建议LZ看一看LDD3中介绍的2.6下编译内核模块的Makefile是怎么写的。

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
3 [报告]
发表于 2009-03-23 16:50 |只看该作者
# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.
ifeq ($(KERNELRELEASE),)

    # Assume the source tree is where the running kernel was built
    # You should set KERNELDIR in the environment if it's elsewhere
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    # The current directory is passed to sub-makes as argument
    PWD := $(shell pwd)

modules:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
        rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
    # called from kernel build system: just declare what our modules are
    obj-m := hello.o
endif

论坛徽章:
0
4 [报告]
发表于 2009-03-23 16:54 |只看该作者
makefile是linux module programing guide那本书上写的,怎么是makefile出错了?

[ 本帖最后由 jazeltq 于 2009-3-23 16:57 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-03-23 17:06 |只看该作者
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX  -c hello.c

单独这一句是不行的

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
6 [报告]
发表于 2009-03-23 17:28 |只看该作者
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX  -c hello.c

你了解这种编译内核模块的方法是那个版本的吗

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
7 [报告]
发表于 2009-03-23 17:29 |只看该作者
makefile是linux module programing guide那本书上写的,怎么是makefile出错了?


你确认一下你看的这本书人家是基于2.4的还是2.6的。这两个版本的编译方法不一样

论坛徽章:
2
申猴
日期:2013-12-26 22:11:31天秤座
日期:2014-12-23 10:23:19
8 [报告]
发表于 2009-03-23 17:37 |只看该作者
Godbach是好人啊

论坛徽章:
0
9 [报告]
发表于 2009-03-23 18:43 |只看该作者
thank you a lot,我知道了,我先看看ldd把,我看的那本书太老了

论坛徽章:
0
10 [报告]
发表于 2009-03-23 19:01 |只看该作者
原帖由 jazeltq 于 2009-3-23 18:43 发表
thank you a lot,我知道了,我先看看ldd把,我看的那本书太老了


网上还有一份文档叫:
Linux kernel module programming guide 有2.6版本的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP