免费注册 查看新帖 |

Chinaunix

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

2.4内核下用Makefile编译hello.c(LDD2例子)的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-17 18:52 |只看该作者 |倒序浏览
我想用Makefile编译linux device drivers (2nd)的hello.c,可惜一直出错,请问一下这个Makefile到底怎么写?我想把代码编译成一个模块,然后加到内核中去。下面是代码:

错误信息:
--------------------------------------------------------------------------------------------------------------
[root@localhost hello]#make
gcc hello.c -o hello
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x1: In function `_start':
../sysdeps/i386/elf/start.S:77: undefined reference to `main'
/tmp/cc6LjFJw.o(.text+0xf): In function `init_module':
: undefined reference to `printk'
/tmp/cc6LjFJw.o(.text+0x2c): In function `cleanup_module':
: undefined reference to `printk'
collect2: ld returned 1 exit status
----------------------------------------------------------------------------------------------------------------


Makefile内容:
---------------------------------------------------------------------------------------------------------------
hello: hello.c
        gcc hello.c -o hello
----------------------------------------------------------------------------------------------------------------


hello.c 内容:
-----------------------------------------------------------------------------------------------------------------
/*                                                     
* $Id: hello.c,v 1.10 2001/07/17 10:30:02 rubini Exp $
*/                                                   
#define MODULE
#include <linux/module.h>

/*                                                        
* These lines, although not shown in the book,           
* are needed to make hello.c run properly even when      
* your kernel has version support enabled               
*/                                                      
                                                         
int init_module(void)      { printk("<1>Hello, world\n"; return 0; }
void cleanup_module(void)  { printk("<1>Goodbye cruel world\n"; }
-----------------------------------------------------------------------------------------------------------------

论坛徽章:
0
2 [报告]
发表于 2006-11-17 20:22 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2006-11-18 09:31 |只看该作者
有书,怎么不把书看明白了?

论坛徽章:
0
4 [报告]
发表于 2006-11-18 15:28 |只看该作者
编译模块,加上 -D__KERNEL__,-DMODULE,还有 -c (这里的模块是目标代码文件,不是已经连接好的可执行程序)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP