最简单的模块编程编译出错了?!新手请教…
2013-11-04 10:47
246 查看
转载▼
标签:编程模块杂谈 |
第一次接触driver,出错了不知如何下手……
-----------------------------------------------------------------
bash-3.1# pwd
/usr/local-data/code/drivers/hello_module
bash-3.1# ls
hello.cMakefile
bash-3.1# cat hello.c
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
static int__init hello_enter(void)
{
printk("Hello World -- enter\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("Hello World -- exit\n");
}
module_init(hello_enter);
module_exit(hello_exit);
MODULE_AUTHOR("Baohua Song");
MODULE_DESCRIPTION("A simplest module!");
MODULE_ALIAS("a simplest module");
bash-3.1# cat Makefile
obj-m := hello.o
bash-3.1# make -C /usr/src/linux-2.6.24M=/usr/local-data/code/drivers/hello_module/ modules
make: Entering directory `/usr/src/linux-2.6.24'
WARNING: Symbol version dump/usr/src/linux-2.6.24/Module.symvers
is missing; modules will have no dependencies andmodversions.
CC /usr/local-data/code/drivers/hello_module/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /usr/local-data/code/drivers/hello_module/hello.mod.o
/usr/local-data/code/drivers/hello_module/hello.mod.c:8: 错误:变量‘__this_module’ 有初始值设定但类型不完全
/usr/local-data/code/drivers/hello_module/hello.mod.c:9:错误:初始值设定项里有未知的字段 ‘name’
/usr/local-data/code/drivers/hello_module/hello.mod.c:9:警告:结构初始值设定项中有多余元素
/usr/local-data/code/drivers/hello_module/hello.mod.c:9: 警告:(在‘__this_module’ 的初始化附近)
/usr/local-data/code/drivers/hello_module/hello.mod.c:10:错误:初始值设定项里有未知的字段 ‘init’
/usr/local-data/code/drivers/hello_module/hello.mod.c:10:警告:结构初始值设定项中有多余元素
/usr/local-data/code/drivers/hello_module/hello.mod.c:10: 警告:(在‘__this_module’ 的初始化附近)
/usr/local-data/code/drivers/hello_module/hello.mod.c:14:错误:初始值设定项里有未知的字段 ‘arch’
/usr/local-data/code/drivers/hello_module/hello.mod.c:14:错误:‘MODULE_ARCH_INIT’ 未声明 (不在函数内)
/usr/local-data/code/drivers/hello_module/hello.mod.c:14:警告:结构初始值设定项中有多余元素
/usr/local-data/code/drivers/hello_module/hello.mod.c:14: 警告:(在‘__this_module’ 的初始化附近)
make: *** 错误 1
make: *** 错误 2
make: Leaving directory `/usr/src/linux-2.6.24'
bash-3.1# ls
hello.chello.mod.chello.oMakefileModule.symvers
bash-3.1# cat hello.mod.c
#include
#include
#include
MODULE_INFO(vermagic, VERMAGIC_STRING);
struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
static const char __module_depends[]
保护DNS服务器十大最有效方法技巧
__attribute_used__
__attribute__((section(".modinfo"))) =
"depends=";
[ 本帖最后由 Kallawa 于 2008-8-25 18:42 编辑]myblog:http://blog.chinaunix.net/u1/52350/showart_441201.html看了你的文章,“要求:已经安装开发工具,在usr/src/下有内核源代码,我这里是安装开发工具时自带的”,请问,“开发根据”具体指的是哪些?
认真比较了源代码和Makefile,没有多大差异的……
/usr/src/linux-2.6.24是linux-2.6.24.tar.bz2直接解压的源码,不知这是否有影响?“开发工具”---回复#3 Kallawa 的帖子需要先编译内核. 具体可以到内核版去看是怎样编译内核的.感觉是编译方法有问题。
试试这个 Makefile:
# Makefile
TARGET=hello
obj-m:=${TARGET}.o
KDIR:=/usr/src/linux-2.6.24
PWD:=$(shell pwd)
default %:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
存为 Makefile,然后在命令行输入:
make
[ 本帖最后由 flw 于 2008-4-22 12:15 编辑]http://bbs.chinaunix.net/viewthread.php?tid=1064471是不是
make -C /usr/src/linux-2.6.24M=/usr/local-data/code/drivers/hello_module/ modules
这句出问了?
要是使用系统内核呢?
/lib/modules/2.6.21.5-smp/build链接到www.dgdaming.com:
build -> /usr/src/linux-2.6.21.5
可并没有/usr/src/linux-2.6.21.5这个文件夹(安装系统的时候要么不带源码,要么删掉了)谢谢xi2008wang,scutan,flw,兔子的回帖……
看了几位的Makefile,个人觉得在make -C /usr/src/linux-2.6.24M=/usr/local-data/code/drivers/hello_module/ modules这句里出问题了!
(KERNEL_DIR:=/lib/modules/$(KERNEL_VERSION)/build链接到/usr/src/linux-$(KERNEL_VERSION))
注意www.hc3600.com,我的机子上的/usr/src/linux-2.6.24是直接解压出来的!
很可能象scutan所说的要编译内核……不知道有没有不编译内核的方法??
附运行flw的Makefile后显示error:
bash-3.1# make
make -C /usr/src/linux-2.6.24SUBDIRS=/usr/local-data/code/drivers/hello_module modules
make: Entering directory `/usr/src/linux-2.6.24'
WARNING: Symbol version dump/usr/src/linux-2.6.24/Module.symvers
is missing; modules will have no dependencies andmodversions.
scripts/Makefile.build:212:目标“/usr/local-data/code/drivers/hello_module/.O”不匹配目标模式
CC /usr/local-data/code/drivers/hello_module/.O
gcc: 没有输入文件
make: *** 错误 1
make: *** 错误 2
make: Leaving directory `/usr/src/linux-2.6.24'
make: *** 错误 2你把 makefile 没搞对吧。
估计是漏了 TARGET 那一行,再要不就是拼错了。
相关文章推荐
- php 模块编译提示libtool出错
- 简单的内核模块编译、加载
- 为Apache编译添加mod_expires模块出错的解决笔记[原创]
- Linux驱动编程编译模块时出现 error:'TASK_NORMAL' undeclared (first use in this function
- 简单学习JNI编程,照搬网上代码编译运行跑通第一步
- unix环境高级编程编译方法 -apue最简单编译方法(第二版)
- Qt简单编程--编译后exe文件的图标
- linux 模块编程的简单示例 helloworld
- 开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。
- 请教MFC的简单问题,新手,需要你们的帮助
- boost 编译 asio 程序,简单socket 编程
- 【内核】:最简单的内核模块编程 -- 一切从这里开始
- 开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。
- JAVA 新手问题: Request 编码编译出错,Unhandled exception type UnsupportedEncodingException
- makefile 循环编译子模块,出错时自动退出
- 编译模块出错:insmod: ERROR: could not insert module module.ko: Invalid parameters
- 内存分配模块编译出错
- 【模块化编程】理解requireJS-实现一个简单的模块加载器
- 编译unix环境高级编程第一个例子出错解决
- Linux驱动编程 step-by-step (六) 用户地址检测 简单模块调试 以及一些杂项