[질문] Module Programming 초보의 계속되는 바보같은 질문입니?

naraping의 이미지

밑에서 답변해주신분들 너무 감사합니다.
제가 무엇을 잘못했는지 모르겠습니다.

소스코드는 다음과 같습니다.

/*  hello-1.c - The simplest kernel module.  */
#include <linux/module.h>  /* 모든 모듈에 필요 */
#include <linux/kernel.h>  /* KERN_ALERT에 필요 */


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

    return 0;
}
void cleanup_module(void)
{
    printk(KERN_ALERT "Goodbye world 1.\n");
}

이것을 문서에 있는 그대로 긁어서 Makefile을 만들라고 하는 것도 긁었는데

TARGET  := hello-1
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc
	
${TARGET}.o: ${TARGET}.c

.PHONY: clean

all: 
     ${CC} ${CFLAGS} -c ${TARGET}.c -o ${TARGET}.o

clean:
    rm -rf *.o

이렇게 하면

[root@NARAPING modulePrograms]# make
rm -rf *.o
라는 메시지만 출력될뿐 실질적인 *.o 파일은 만들어 지지 않고 있습니다.
Makefile에 추가해야하는 내용이 더 있는건가요?

McKabi의 이미지

같은 오류가 계속 나오고 있다는 말씀인가요?

뭔가 미끼를 던져야 입질을 하죠. :wink:

새로 올라오는 글을 보고 있는데 같은 주제로 계속 새 글을 쓰고 계시네요.
먼저 올렸던 글에 계속 따라서 쓰시는게 좋습니다.

ㄲ ㅏ ㅂ ㅣ / M c K a b i / 7 7 r b i / T o D y

naraping의 이미지

음....

오비젝트 파일이 생기지 않는데...어떻게 해야하나요?

make 관련해서는 인터넷 서점에 주문한 책을 보려고 기다리는 중인데, 답변좀 주세요.

hello-1.o 파일이 만들어지지않고, rm -rf *.o만 출력되네요.

raymundo의 이미지

켁, 컴파일 에러 얘기가 아니라 make 얘기였군요.. -_-;

make 유틸리티에 대한 문서를 아무거나 찾아보시면 나옵니다만, make 뒤에 별다른 인자를 주지 않으면 makefile 에서 제일 처음 발견되는 target 을 생성합니다. 따라서 make clean 과 동일한 결과가 나오는거죠.

hello-1.o 를 만들고 싶으면 make hello-1.o 라고 해 보세요.

아니면 Makefile 에서 제일 첫번째 타겟으로

all: hello-1.o

와 같은 식으로 적어두던가요.

좋은 하루 되세요!

naraping의 이미지

그렇게 고쳤지만.....

[root@NARAPING modulePrograms]# make
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include   -c -o hello-1.o hello-1.c
In file included from /lib/modules/2.4.18-4/build/include/linux/config.h:4,
                 from /lib/modules/2.4.18-4/build/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/autoconf.h:1: #error Invalid kernel header included in userspace
make: *** [hello-1.o] 오류 1

위와 같은 오류가 나는데......

raymundo의 이미지

그렇게 고쳤지만이 아니죠. 적어도 make 쪽은 해결되었잖아요~ ^^

이제야 본격적인 소스코드의 문제인데... 이건 저는 모르겠으니 다른 분이 답해 주시겠지요. ^^;;;

좋은 하루 되세요!

Ghacker의 이미지

TARGET := hello-1
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC := gcc

${TARGET}.o: ${TARGET}.c

all: hello-1.o

.PHONY: clean

clean:
rm -rf *.o

위의 makefile을 그대로 두면 당연히 rm -rf *.o만 실행이 되겠죠.
그 위의 "all: ~~~" 이 부분을 .PHONY 아래로 옮기시구요..

all: ${CC} ${CFLAGS} -c ${TARGET}.c -o ${TARGET}.o

이렇게 바꿔보세요.

naraping의 이미지

[root@NARAPING modulePrograms]# make all
make: *** No rule to make target `gcc', needed by `all'.  멈춤.
[root@NARAPING modulePrograms]# make
make: *** No rule to make target `gcc', needed by `all'.  멈춤.

죄송하지만 이번에는 이런 오류가 나는데............
기초적인걸로 물어봐서 죄송합니다~~~

raymundo의 이미지

Ghacker wrote:

all: ${CC} ${CFLAGS} -c ${TARGET}.c -o ${TARGET}.o

이 아니라

all:
     ${CC} ${CFLAGS} -c ${TARGET}.c -o ${TARGET}.o

로 적어주시면 될 겁니다. (all: 옆은 비우고 다음 줄에 탭으로 시작한 후 나머지 내용)

좋은 하루 되세요!

naraping의 이미지

[root@NARAPING modulePrograms]# make
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes
-isystem /lib/modules/`uname -r`/build/include -c hello-1.c -o hello-1.o
In file included from /lib/modules/2.4.18-4/build/include/linux/config.h:4,
                 from /lib/modules/2.4.18-4/build/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/autoconf.h:1: #error Invalid kernel header included in usersp
ace
make: *** [all] 오류 1

위와 같은 오류가 나는데, 이게 커널 모듈의 버젼이 보함되지 않아서 그런건가요?