Find the answer to your Linux question:
Results 1 to 9 of 9
hello, i was trying to write my first module. i am using the debian GNU/Linux 5.0 \n\l and my kernel version is : 2.6.26-2-686. blow is my Makefile , the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    14

    Makefile error


    hello, i was trying to write my first module. i am using the debian GNU/Linux 5.0 \n\l and my kernel version is : 2.6.26-2-686. blow is my Makefile , the only problem is i don't understand what's the contents. copied it from a site. dont know if that's why it's giving the errors.

    Makefile:

    obj-m = foo.o
    KVERSION = $(shell uname -r)
    all:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean



    here is the error i am getting when i try to compile my module with the command make:

    make -C /lib/modules/build M = /usr/src modules
    make: *** empty variable name. stop.
    make: *** [all] Error 2

    please can anyone explain to me what the contents of the Makefile is and how to corrrect the errors?

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Here's a generic Makefile that I use:

    Code:
    obj-m += test.o
    
    all:
    <tab>	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    <tab>	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    Note the the lines that start with make have to be tabbed in
    plus make make sure you have the kernel devel/source files installed
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    May 2009
    Posts
    14
    hello,

    thanks for the reply. the one thing that keeps bothering me is the last statement of your reply "make sure you have the kernel devel/source files installed " how do i ensure that that is in place? do i have to download a source, compile and configure it before i could start writing my module?

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Well you should be able to go to your file browser and look up the path from your makefile

    /lib/modules/$(shell uname -r)/build

    the value of $(shell uname -r) can be found by typing uname -r in a terminal window...for instance on my machine my path is

    /lib/modules/2.6.29.1-desktop-4mnb/build

    If the kernel development files are installed this path will exist...Gerard4143
    Make mine Arch Linux

  5. #5
    Just Joined!
    Join Date
    May 2009
    Posts
    14
    thanks for the fast replies,

    now, i am in more confusion as i have just tried a few different things.
    first: when i tried to check the /lib/module on the browser, i couldn't because i could't connect to the internet. so, i decided to try it wih another distro, this timeUbuntu 8.04.1 \n \l
    and the version is 2.6.24-19-generic. first i decided to install the gcc as i noticed this distro can't compile codes. so i tried the apt-get install 2.6.24-19-generic hearders
    . but it gave the error "E: Couldn't find package 2.6.24-19-generic"

    second : when i then ran my module and compiled it using the 'make' command, i got the error:
    root@henry-desktop:/home/henry/test# make
    make: Nothing to be done for `all'.

    referring to the all in my Makefile. could this be a similar reason you gave that perhaps the source is not available?

    Makefile:

    obj-m = hello.o
    KVERSION = $(shell uname -r)
    all:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean


    thanks again for the fast replies.

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by admindesk View Post
    thanks for the fast replies,

    now, i am in more confusion as i have just tried a few different things.
    first: when i tried to check the /lib/module on the browser, i couldn't because i could't connect to the internet. .
    That was file browser like Nautilis. or the file explorer in windows..G4143
    Make mine Arch Linux

  7. #7
    Just Joined!
    Join Date
    May 2009
    Posts
    14
    Hello,

    sorry i don't understand what you meant by that was file browser like Nautilis or the file explorer in windows but if you mean to ask my browser, it's Mozilla firefox. and by the way, i ran the/lib/modules/$(shell uname -r)/build for the ubuntu distro and it did show the source existed. here is a link to what's in there: "file:///lib/modules/2.6.24-19-generic/build/"

    now, i am wondering what to do next since this source exist?

    thanks for your frequent and quick responses. I appreciate

  8. #8
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Well if that path is valid you should have the required files to compile a kernel module. Just make sure your logged in as root and then call make and it should produce a file called foo..ko which is your kernel module...G4143

    here's a link that got me started:

    The Linux Kernel Module Programming Guide
    Make mine Arch Linux

  9. #9
    Just Joined!
    Join Date
    May 2009
    Posts
    14
    hello,

    that is my dilemma as well, because that path is valid yet it keeps giving this error:

    root@henry-desktop:/home/henry/test# make
    make: Nothing to be done for `all'.


    could it be something in my Makefile? not sure though because i don't understand the contents of the Makefile. i only copied thos contents from a source and don't know what it contains. i have seen other Makefile versions with KDIR and now i seen KVERSION, what does these contents contain. could you explain it to me, maybe i have to change something.

    Makefile:

    obj-m = hello.o
    KVERSION = $(shell uname -r)
    all:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean


    how many tab spaces must be given to the make line? 1, 2..
    what does the all and clean mean? and what is the line make -C supposed to do? if i could understand what it contains maybe i am supposed to change something but not sure because it kept complaining about the 'all' in my Makefile.

    thanks for the continuous replies.

Posting Permissions

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