You're trying to compile your module with plain gcc
with none of the
surrounding kbuild framework. You might have gotten something to work in the
past with this approach, but it is painful horrible awful to try to maintain
a module using anything other than pure-kbuild Makefile
approaches. I've
wasted too much of my life fighting against kbuild and I don't want the same to
happen with you -- embrace kbuild and let it help you build your module. Please
read Documentation/kbuild/modules.txt
before writing another line of code.
What you need to do is create a Makefile
for your module. Its contents should
look like this:
ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
obj-m := modulename.o
else
# normal makefile
KDIR ?= /lib/modules/`uname -r`/build
default:
$(MAKE) -C $(KDIR) M=$$PWD
endif
I know it's a lot more complicated than most Makefile
s you're used to seeing,
but it serves a dual-purpose. If you just run make
in your directory, it'll
re-invoke make
to use the kbuild mechanism from the currently-running kernel
(assumed to at least have a symlink from /lib/modules/.../build
to the
correct location).
The re-invoked make
command ($(MAKE)
) will properly build your module and
save you more time than you can ever appreciate. (Really.)
Keep Documentation/kbuild/modules.txt
by your side while making this work.
Note: Documentation/kbuild/modules.txt
may be available at your linux system at /usr/share/linux-headers-$(uname -r)/Documentation/kbuild/modules.txt
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…