Results 1 to 5 of 5

Thread: Having trouble compiling a hello-world Linux kernel module

  1. #1
    Join Date
    Mar 2007
    Beans
    1,052

    Having trouble compiling a hello-world Linux kernel module

    I'm trying to compile a Linux kernel module called hello-2.c using the command "make -C /lib/modules/$(uname -r)/build M=${PWD} modules" (without the quotes) (which I found online), and the following is the (seemingly successful) output.:
    Code:
    make: Entering directory `/usr/src/linux-headers-3.2.0-4-amd64'
      Building modules, stage 2.
      MODPOST 0 modules
    make: Leaving directory `/usr/src/linux-headers-3.2.0-4-amd64'
    However, I don't see a hello-2.ko (in the same folder or anywhere else for that matter).

    Everything I am doing is within a folder/directory called "thefolder" (without the quotes) in the "/tmp" directory (without the quotes).

    Could someone please tell me why I can't see a hello-2.ko, and what to do to get it?
    Apps for Ubuntu (outdated) ---> http://cid-23a283fc1010a1bb.skydrive...%20Wine|6?uc=1
    Use Mnemosyne to Study for School!

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

    Re: Having trouble compiling a hello-world Linux kernel module

    Your instructions do not indicate that you set obj-m to the name of the expected object file name. Create a Makefile to simplify the process of building the module. For additional info, read here: http://ubuntuforums.org/showthread.p...95#post8187295

    P.S. In your particular case, you should probably be using:
    Code:
    obj-m += hello-2.o
    
    ...

  3. #3
    Join Date
    Mar 2007
    Beans
    1,052

    Re: Having trouble compiling a hello-world Linux kernel module

    Quote Originally Posted by dwhitney67 View Post
    Your instructions do not indicate that you set obj-m to the name of the expected object file name. Create a Makefile to simplify the process of building the module. For additional info, read here: http://ubuntuforums.org/showthread.p...95#post8187295

    P.S. In your particular case, you should probably be using:
    Code:
    obj-m += hello-2.o
    
    ...
    I don't know what I did differently, but using your Makefile syntax worked. Thanks!

    Having said that, though, why doesn't "obj-m += hello-2.ko" (without the quotes) work (instead of "obj-m += hello-2.o" - without the quotes)?:
    Code:
    obj-m += hello-2.o # Why doesn't "obj-m += hello-2.ko" (without the quotes) work?
    
    all:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    I ask, since I thought that the .ko file extension became the successor of the .o file extension.

    Also, could you please elaborate about what that Makefile syntax does (specifically)?
    Apps for Ubuntu (outdated) ---> http://cid-23a283fc1010a1bb.skydrive...%20Wine|6?uc=1
    Use Mnemosyne to Study for School!

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

    Re: Having trouble compiling a hello-world Linux kernel module

    I would imaging that the .o (regular object file) is an intermediate product that is produced before the kernel module (.ko) file is produced.

    As for Makefiles, in a nutshell, it is a collection of zero or more declarations (e.g. obj-m), and then 'rules' (e.g. all and clean) that can be invoked using the command make, followed by the rule name. If a rule name is not specified, then the first rule in the file is executed. A Makefile can make one's life easier so that complicated commands do not have to repeatedly be entered on the command line.

    For (a lot) more about Makefiles, read here: http://www.gnu.org/software/make/manual/make.html

  5. #5
    Join Date
    Mar 2007
    Beans
    1,052

    Re: Having trouble compiling a hello-world Linux kernel module

    Quote Originally Posted by dwhitney67 View Post
    I would imaging that the .o (regular object file) is an intermediate product that is produced before the kernel module (.ko) file is produced.

    As for Makefiles, in a nutshell, it is a collection of zero or more declarations (e.g. obj-m), and then 'rules' (e.g. all and clean) that can be invoked using the command make, followed by the rule name. If a rule name is not specified, then the first rule in the file is executed. A Makefile can make one's life easier so that complicated commands do not have to repeatedly be entered on the command line.

    For (a lot) more about Makefiles, read here: http://www.gnu.org/software/make/manual/make.html
    Thanks again!
    Apps for Ubuntu (outdated) ---> http://cid-23a283fc1010a1bb.skydrive...%20Wine|6?uc=1
    Use Mnemosyne to Study for School!

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
  •