Reputation: 1717
Before anyone points this out, a similar question was answered here before: Compiling Linux Kernel Module With A Custom Header
I have the same issue. I created my own set of structs and functions and defined them in a C file. Then I created a header file of the same name and included it in a module. Then I created the Makefile:
obj-m += themodule.o
themodule-objs := the-module.o my-code.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
My custom files are my-code.c and my-code.h.
When I tried to compile the module, I received a ton of warning, telling me that all the functions from my-code.c were undefined in the-module.c. When I tried to load the module, I received errors, telling me that the function calls to my-code.c were "unknown symbols". I tried the solution mentioned in the linked question (see Makefile), but that did not do the trick for me. Any thoughts?
Upvotes: 1
Views: 465
Reputation: 1608
The order in themodule-objs matters. Try this:
obj-m += themodule.o
themodule-objs := my-code.o the-module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Upvotes: 2