[Techtalk] compiling an external kernel module

Mary mary-linuxchix at puzzling.org
Thu Apr 8 07:10:09 EST 2004


On Wed, Apr 07, 2004, Carla Schroder wrote:
> O Great Kernel Geeks,
> 
> I've been butting my head on this for a week now, therefore I appeal
> to greater minds than mine. How do you compile a kernel module that is
> not included in the kernel sources? Do you have to get the sources,
> and write a makefile, and invoke gcc, and horrid stuff like that?
> What's a person who wants to run a hardware device that is not
> supported in the kernel to do?

Generally you need the kernel header files and the source of your
external module.

The header files are a subset of the source which defines which
functions are available. It's just like when you compile other C
programs, you need the libc header files -- libc6-dev or similar --
installed, but not the entire libc source.

For people who built their own kernel, the headers are in the kernel
sources. For people using a distribution kernel, there's always a
separate package with the header files. In Debian these packages are
called kernel-headers-VERSION and I imagine it isn't much different with
other distros.

Normally external modules are distributed with an existing makefile and
you need to set some environment variables that point it at your kernel
headers/soures. In fact, I don't think I've ever seen one come without
its own makefile.

Guessing what the environment variables are called is another kettle of
fish. It's often KSRC or KERNSRC but can vary. Often there will be a
README or similar distributed with your module sources although on the
odd occasion I've been forced to read parts of (but not write!) the
makefile. It may also be an option to ./configure

Once you figure out how to point the installer at the kernel headers,
it's usually a ./configure, make, make install process.

Which module are you trying to build?

-Mary


More information about the Techtalk mailing list