Compiling a c program into .ko

Warner Losh imp at bsdimp.com
Thu Mar 25 07:35:44 UTC 2021


On Wed, Mar 24, 2021 at 12:23 AM Andrew Mitchell via freebsd-drivers <
freebsd-drivers at freebsd.org> wrote:

> Hello,
> I haven’t been able for the last few weeks to understand why my file.c
> won’t compile into a file.ko.
> I include <bsd.kmod.mk> in Makefile, but make returns an error which I
> can’t explain. In all the documentation I have come across nothing is said
> of SYSDIR, which is reported in the error message.
> If you have met with this problem and found a practical solution, please
> send me an answer so that I can unearth this arcana.
>

To build a kernel module, you need a copy of the kernel source. You can get
it from the 'src' git repo under sys. so if you cloned a work tree to
/foo/bar/FreeBSD/src/sys, you'd set SYSDIR to /foo/bar/FreeSBD/src/sys in
your shell environment, or type it each time on the make command line.
Alternatively, you can put your kernel sources in /usr/src/sys and it will
pick them up automatically.

This should be documented in the build(7) man page, but is conspicuous by
its absence.  I'll fix that shortly, but this should get you to the next
step.

Warner


> Cheers,
> Andy
>
>
>
> Envoyé de mon iPhone
> _______________________________________________
> freebsd-drivers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-drivers
> To unsubscribe, send any mail to "freebsd-drivers-unsubscribe at freebsd.org"
>


More information about the freebsd-drivers mailing list