문제

I would like to compile a simple character device module depending on a custom header. The folder is thus organized,

+ mymod.c
| customized-header.h
| customized-header.c
| Makefile

In mymod.c, the header is thus used,

#include "customized-header.h"

In Makefile:

obj-m := mymod.o
mymod-objs := customized-header.o
KVERSION = $(shell uname -r)
PWD = $(shell pwd)
all:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

Everything should work fine, the module gets compiled without problem, I can load the module through sudo insmod, but the module doesn't work properly. When I checked nm mymod.ko, there are a lot of vars and functions are missing. It looks as if it stopped after linking customized_header.o. If I remove this header and its function, say no header function calls from the module, it compiles perfectly with desired result.

Could you see what went wrong here?

도움이 되었습니까?

해결책

The problem resides in the Makefile. Due to the link here, I changed it into

obj-m: mymodko.o
mymodko-obj: customized-header.o mymod.o

It now works fine. So the question was the naming of module object. We need to specify different names as in this case mymodko.o and mymod.o.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top