免费注册 查看新帖 |

Chinaunix

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

内核模块编译出错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-23 14:38 |只看该作者 |倒序浏览
我是安装书上照搬下来的:
OS:CENTOS 4.5
KERNEL:2.6.9-42.ELsmp

Makefile:

  1. # Makefile2.6
  2.         obj-m := hellomod.o
  3.         CURRENT_PATH := $(shell pwd)
  4.         LINUX_KERNEL := $(shell uname -r)
  5.         LINUX_KERNEL_PATH := /lib/modules/$(LINUX_KERNEL)/build
  6. all:
  7.         make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
  8. clean:
  9.         make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
复制代码


编译的时候提示:

  1. make -C /lib/modules/2.6.9-42.ELsmp/build M=/root/c_dir/hellomode modules   
  2. make[1]: Entering directory `/usr/src/kernels/2.6.9-42.EL-smp-i686'
  3. make[2]: *** No rule to make target `/root/c_dir/hellomode/hellomod.c', needed by `/root/c_dir/hellomode/hellomod.o'.  Stop.
  4. make[1]: *** [_module_/root/c_dir/hellomode] Error 2
  5. make[1]: Leaving directory `/usr/src/kernels/2.6.9-42.EL-smp-i686'
  6. make: *** [all] Error 2
复制代码

论坛徽章:
0
2 [报告]
发表于 2008-11-23 16:30 |只看该作者

回复 #1 rainballdh 的帖子

make file 的问题吧?
将make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules修改为下面的看看(clean 也有问题):
$(MAKE) -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules

论坛徽章:
0
3 [报告]
发表于 2008-11-23 18:40 |只看该作者
原帖由 chenbdchenbd 于 2008-11-23 16:30 发表
make file 的问题吧?
将make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules修改为下面的看看(clean 也有问题):
$(MAKE) -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules

错误还是一样
不是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
4 [报告]
发表于 2008-11-23 19:00 |只看该作者
贴给LZ一个LDD3上常用的Makefile,试一下好用不。偶现在自己写模块,基本都用这个Makefile。
# 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/`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 := netbase.o
endif

论坛徽章:
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
5 [报告]
发表于 2008-11-23 19:01 |只看该作者
替换
    obj-m := netbase.o

中的netbase.o为你自己的即可。偶用起来没有问题

论坛徽章:
0
6 [报告]
发表于 2008-11-23 20:34 |只看该作者
谢谢各位,是我自己不够细心

论坛徽章:
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 [报告]
发表于 2008-11-23 21:28 |只看该作者
呵呵,LZ可否分享一下你的问题所在,让别人在以后也可以注意啊。

论坛徽章:
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
8 [报告]
发表于 2008-11-23 21:36 |只看该作者
是参与编译的文件位置不对吗

论坛徽章:
0
9 [报告]
发表于 2008-11-24 09:48 |只看该作者
原帖由 Godbach 于 2008-11-23 21:28 发表
呵呵,LZ可否分享一下你的问题所在,让别人在以后也可以注意啊。

Makefile里面写的是:
obj-m := hellmod.o
而我的C文件是hellomod.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
10 [报告]
发表于 2008-11-24 09:50 |只看该作者
原帖由 rainballdh 于 2008-11-24 09:48 发表

Makefile里面写的是:
obj-m := hellmod.o
而我的C文件是hellomod.c
不一致,导致上买你的错误。自己太粗心了


呵呵,是啊。有时总是被这样的错误困扰半天。 另外,你1楼上写的又是正确的吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP