Page 2 of 2 FirstFirst 12
Results 11 to 11 of 11

Thread: Programming kernel modules

  1. #11
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: Programming kernel modules

    As I was reading through the various posts, I was surprised that that it took 9 posts before the solution became apparent!

    'gcc' should NOT be used directly to compile kernel modules. Use the procedure at shown in the previous post, or alternatively create a Makefile that encompasses everything that is required to build the module. Here's an example:
    Code:
    obj-m += hello.o
    
    all:
            $(MAKE) -C /lib/modules/`uname -r`/build M=$(PWD) modules
    
    clean:
            $(MAKE) -C /lib/modules/`uname -r`/build M=$(PWD) clean
            $(RM) Module.markers modules.order
    P.S. It is always best to use the command 'uname -r' to derive the current kernel version, rather than hard-coding the value. If a new kernel is added later (or if a different version exists on another platform), and the kernel version number is hard-coded in many scripts and/or Makefiles, it would be a bitch to go back and edit those.
    Last edited by dwhitney67; June 27th, 2008 at 07:56 AM.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •