1

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?

2
  • What happens when you change the obj-m line to: obj-m := mymod.o customized-header.o? Commented Oct 1, 2013 at 23:00
  • @PeterL. Well, obj-m is to generate a module. When I added customized-header.o, some more files are generated: like customized-header.ko. In the meantime, mymod.ko is still the same. Here I would like only one module, which is mymod.ko, the customized-header works like a library for the module. Commented Oct 2, 2013 at 11:41

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@BenjaminLeinweber I need to wait for another 20 hours to accept my own answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.