Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] Having trouble compiling a Linux kernel module

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

[SOLVED] Having trouble compiling a Linux kernel module

#1 Post by s3a »

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: Select all

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). I'm Using Debian GNU/Linux 7.6.

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?
Last edited by s3a on 2014-08-29 17:17, edited 1 time in total.
Use Mnemosyne to Study for School!

User avatar
levlaz
Posts: 179
Joined: 2012-09-27 12:06
Location: San Francisco, CA

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

#2 Post by levlaz »

Can you put a copy of your module and makefile here?

Thanks!
Lev
Best,

Lev
Blog

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

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

#3 Post by s3a »

I don't know what I did differently, but I successfully got it to work!

Here is the hello-2.c file.:

Code: Select all

/*
* hello−2.c − Demonstrating the module_init() and module_exit() macros.
* This is preferred over using init_module() and cleanup_module().
*/

#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */

static int __init hello_2_init(void)
{
	printk(KERN_INFO "Hello, world 2\n");
	return 0;
}

static void __exit hello_2_exit(void)
{
	printk(KERN_INFO "Goodbye, world 2\n");
}

module_init(hello_2_init);
module_exit(hello_2_exit);
Here is the Makefile.:

Code: Select all

obj-m += hello-2.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
Use Mnemosyne to Study for School!

Post Reply