커널 모듈 프로그래밍시 에러 입니다.

소맛라면의 이미지

hello.c 파일 소스는

#include <linux/kernel.h>
#include <linux/module.h>

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif

int init_module()
{
printk("Hello, world - this is the kernel speaking\n");
return 0;
}

void cleanup_module()
{
printk("Short is the life of a kernel module\n");
}

Makefile 소스는

CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c

이렇게 하고
make 하면
아래와 같이 나옵니다.

gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c hello.c
In file included from hello.c:2:
/usr/include/linux/module.h:60: parse error before `atomic_t'
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:62:parse error before `}'
/usr/include/linux/module.h:62:warning: data definition has no type or storage class
/usr/include/linux/module.h:91:parse eooro before `}'
hello.c: In function `init_module':
hello.c:11: implicit declaration of function `printk'

라고 나옵니다. 다연히 오브젝트 파일은 생성 되지 않고요ㅜㅜ

익명 사용자의 이미지

-I /usr/src/linux-2.4.20-8/include/linux 저같은 경우고요

-I /님이 설치한 리눅스 소스경로를 적어서 옵션에 추가해주심

못 찾았던 함수들을 찾아서 제대로 컴파일 될겁니다.

수고하세요

소맛라면의 이미지

어디에 경로를 추가 하라는지 잘 몰라서,
#include </linux/module.h> ----->
#include </usr/src/linux-2.4/include/linux/module.h>
로 바꾸었습니다.

그랬더니 이번에는 관련 header파일 같은데,
/usr/include/linux/spinlock.h:131: parse error before `*'
라고 에러가나는군요..
아참그리고
/usr/src/include/linux 내에는 module.h가 존재 하더군요..;;

무엇을 위해 사는가..

mach의 이미지

wjdguddnr wrote:

...
Makefile 소스는

CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c

...

커널 버전이 2.4.x지요? 2.6은 좀 다르지만 Makefile을 다음과 같이 바꾸세요.

TARGET	:= hello
INCLUDE	:= -I/lib/modules/`uname -r`/build/include
CFLAGS	:= -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
CC	:= gcc

${TARGET}.o: ${TARGET}.c
	$(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c

* 그리고, /lib/modules/`uname -r`/build/include 디렉터리에 도대체 뭐가 있는지 조사해보세요.
즉, /lib/modules/`uname -r`/build/ 이 디렉터리는 뭐하는데 쓰는지 조사해 보세요.

* 혹시나 1) `uname -r`에서 "`"는 키보드 "~"키에 있는 것입니다.
* 혹시나 2) $(CC) .... 줄 입력시 앞에 칸은 TAB키로 입력합니다.

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

소맛라면의 이미지

위에 처럼 Makefile을 만들었는데
결과는 같내요..무엇때문에 문제가 생긴걸까요.
커널 버전이 너무 낮은 걸까요???
커널 버전은 2.4.13-8입니다.
리눅스를 다시 깔아 봐야 겠습니다..

VLC를 설치한다고.이것 저것 패키지를 깔았는데
그것과 관련이 있을지도..모르겠네요...답변하신분들 나주엥 다시 뵙지요^^

무엇을 위해 사는가..