노무현 대통령 배너


2006. 7. 20. 13:29

[본문스크랩] Kernel Version 2.6.X에서 모듈 프로그래밍 방법

/* Hello.c */

#include
#include

int init_module(void)
{
printk("<1>Hello world 1.n");
return 0;
}


void cleanup_module(void)
{
printk("Goodbye world 1.n");
}

Compile하고~

# insmod hello.o
insmod: error inserting 'hello-1.o': -1 Invalid module format

Kernel Version 2.6에서부터 Module은 .O가 아니라 .KO형태로 제공됩니다.

그래서 소스(Hello.c)를 아래와 같이 바꾸어 주어야 합니다.

/* 수정된 hello.c */
#include // Needed for the __init macros
#include // Needed by all modules
#include // Needed for KERN_ALERT

static int __init hello_2_init(void)
{
printk(KERN_ALERT "Hello, worldn");
return 0;
}


static void __exit hello_2_exit(void)
{
printk(KERN_ALERT "Goodbye, worldn");
}

module_init(hello_2_init);
module_exit(hello_2_exit);
MODULE_LICENSE("GPL");

/*Makefile*/ --> make 파일명 반드시 대문자 Makefile로 쓸것!!

KSRC=/lib/modules/2.6.4/build
obj-m = hello.o

build:
make -C $(KSRC) SUBDIRS=`pwd` modules