日期:2014-05-16  浏览次数:20629 次

LDD2中hello world的问题
下面是hello.c和对应的Makefile:(kernel2.4)

hello.c
--------------------------------------------------
#include   <linux/kernel.h>
#include   <linux/module.h>
 
int   init_module(void)
{
        printk( "Hello,World!\n ");
        return   0;
}
 
        void   cleanup_module(void)
{
        printk( "Goodbye   cruel   world   \n ");
}
 
MODULE_LICENSE( "GPL ");
---------------------------------------------------


Makefile
---------------------------------------------------
CC=gcc
KERNELDIR=/usr/src/linux-$(shell   uname   -r)

MODCFLAGS:=-Wall   -DMODULE   -D__KERNEL__   -DLINUX   -I   $(KERNELDIR)/include
 
hello.o:hello.c   /usr/include/linux/version.h
 
  $(CC)   $(MODCFLAGS)   -c   hello.c
 
clean:
  rm   -f   *.o
----------------------

希望大家帮忙改一下Makefile,来适应下面的要求:
修改后目录结构如下(其中h和hello是同一级的目录):
----------------------
/h/hello.h
/hello/hello.c
            /Makefile
----------------------
现在hello.c需要包含hello.h这个文件,怎么改Makefile?


------解决方案--------------------
如果只是hello.c中用到,那应该只要在$(CC)...中加入 -Ihello.h的路径 即可。
------解决方案--------------------
建议到网上找Makefile的介绍系统的看看,在Linux下开发,不熟悉Makefile,两个字--不行