Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
hey all, I am trying to compile a test module (hello) to learn how to do it. I was trying to follow the instructions here tldp.org/LDP/lkmpg/2.6/html/lkmpg.html which didn't work. I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2013
    Posts
    5

    compiling test module


    hey all,

    I am trying to compile a test module (hello) to learn how to do it. I was trying to follow the instructions here tldp.org/LDP/lkmpg/2.6/html/lkmpg.html which didn't work. I get error 2, file not found in /usr/src/linux-headers-3.2.0-4-common/arch/x86/Makefile

    I tried also using the directions here: linuxforums.org/forum/kernel/61673-how-write-my-makefile-for-a-hello-kernel-module.html

    However, I am getting the exact same error. I found a post from idera (SQL monitoring softeare I think) stating a bug in the >2.6.29 kernels that have the architecture specific module directories (wiki.r1soft.com/display/kb/Compiling+a+module+on+Debian+with+Linux+Kernel+2.6 .29+and+higher)

    I dont know what is wrong and I'm sure there is something simple and stupid I have overlooked. Can someone show me what's wrong?

    Makefile:
    Code:
    obj-m	:= hello-1.c
    
    KDIR	:= /lib/modules/$(shell uname -r)/build
    PWD	:= $(shell pwd)
    
    default:
    	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    I checked the Makefiles for virtual box on that VM and those seem to reference /lib/modules/<kernel>/build as well so I don't understand what I am doing wrong.
    Last edited by atreyu; 04-23-2013 at 02:41 AM. Reason: added links on behalf of OP

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    Whats your distro ? Whats the output of 'uname -r' ? Did you install kernel-devel and kernel-header packages ?
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  3. #3
    Just Joined!
    Join Date
    Apr 2013
    Posts
    5
    I am running the 3.2.0-4 kernel on 64 bit Debian wheezy (RC1 is the current release I think) I have the Linux headers installed and I should have kernel-devel installed but I'll double check when I get home from work. I do also have the package build-essentials installed.

  4. #4
    Just Joined!
    Join Date
    Apr 2013
    Posts
    5
    Quote Originally Posted by cmattv View Post
    I am running the 3.2.0-4 kernel on 64 bit Debian wheezy (RC1 is the current release I think) I have the Linux headers installed and I should have kernel-devel installed but I'll double check when I get home from work. I do also have the package build-essentials installed.
    I cant seem to find the kernel-devel package. I've tried that and linux-kernel-devel.

    I do have the headers. Do you know what this package is called for Debian?

  5. #5
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    I use Fedora , there its known as kernel-devel - I think linux-kernel-devel should the one for Debian.

    HTML Code:
    /lib/modules/
    You said, your are using 64-bit - Can you check /lib64/modules ?

    https://help.ubuntu.com/community/Kernel/Compile
    Customizing & Installing Linux Kernel on Debian Wheezy | Biboroku

    I had some issues with Fedora while creating kernel modules- what I used to do is - just ignore existing kernel - download the latest stable from kernel.org and install that kernel with old
    configuration (make oldconfig) and then update grub menu with new kernel . Reboot and login - now kernel dev becomes much easier
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  6. #6
    Just Joined!
    Join Date
    Apr 2013
    Posts
    5
    hmm i don't have /lib64/modules. I only have ld-linux-x86-64.so.2 in /lib64. In /lib I have a modules directory and in that I have a 3.2.0-4-amd64 and 3.2.0-4-rt-amd64

    Unfortunately I manually compiled some applications and I don't remember which ones. I'd prefer not to replace the kernel every time I want to make a module for it.

    did I make a mistake in the makefile? is there some setting I missed? I tried linux-kernel-devel as well and that package couldn't be found either.

  7. #7
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    Quote Originally Posted by cmattv View Post
    hmm i don't have /lib64/modules. I only have ld-linux-x86-64.so.2 in /lib64. In /lib I have a modules directory and in that I have a 3.2.0-4-amd64 and 3.2.0-4-rt-amd64

    Unfortunately I manually compiled some applications and I don't remember which ones. I'd prefer not to replace the kernel every time I want to make a module for it.

    did I make a mistake in the makefile? is there some setting I missed? I tried linux-kernel-devel as well and that package couldn't be found either.
    Makefile seems fine to my eyes. I think its problem with missing kernel src. I'll try to find a Ubuntu/Debian VM and check this out.
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  8. #8
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,527
    The Debian package for the Linux source code is linux-source
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  9. #9
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    Okay installed debian on VMware box. Yes,even i got the same error message.

    Then I did
    Code:
    root@debian:/home/laks# apt-get install linux-headers*
    It installed some different architecture header files -
    You may want to remove the unnecessary ones.

    Now I can do this !
    Code:
    root@debian:/home/laks# make
    make -C /lib/modules/2.6.32-5-amd64/build M=/home/laks modules
    make[1]: Entering directory `/usr/src/linux-headers-2.6.32-5-amd64'
      CC [M]  /home/laks/hello.o
      Building modules, stage 2.
      MODPOST 1 modules
      CC      /home/laks/hello.mod.o
      LD [M]  /home/laks/hello.ko
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-5-amd64'
    Code:
    #cat Makefile 
    obj-m += hello.o
    
    all:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    
    #root@debian:/home/laks# cat hello.c 
    /*  
     *  hello-1.c - The simplest kernel module.
     */
    #include <linux/module.h>	/* Needed by all modules */
    #include <linux/kernel.h>	/* Needed for KERN_INFO */
    
    int init_module(void)
    {
    	printk(KERN_INFO "Hello world 1.\n");
    
    	/* 
    	 * A non 0 return means init_module failed; module can't be loaded. 
    	 */
    	return 0;
    }
    
    void cleanup_module(void)
    {
    	printk(KERN_INFO "Goodbye world 1.\n");
    }
    So Its a problem with missing correct header files. Install only required packages via apt-get install
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  10. #10
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,527
    I've just run apt-cache policy linux-headers* and there's one or twenty of them so a trick to install things related to your running architecture is to use back ticks and run the uname command. For example
    Code:
    apt-cache policy linux-headers-`uname -r`
    on my Siduction box returns
    Code:
    linux-headers-3.8-8.towo-siduction-amd64:
      Installed: 3.8-12
      Candidate: 3.8-12
      Version table:
     *** 3.8-12 0
            500 http://ftp.spline.de/pub/siduction/base/ unstable/main amd64 Packages
            100 /var/lib/dpkg/status
    This can also be applied to things like apt-get install. I assume that something similar would work in the Red Hat world?
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

Page 1 of 2 1 2 LastLast

Posting Permissions

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