All of lore.kernel.org
 help / color / mirror / Atom feed
* Problem with module spanning from multiple files
@ 2012-07-18  7:34 aleksey
  2012-07-18  8:14 ` Philipp Ittershagen
  0 siblings, 1 reply; 6+ messages in thread
From: aleksey @ 2012-07-18  7:34 UTC (permalink / raw)
  To: kernelnewbies

Hello. 

I want to build kernel module which consist from two files. 

test.c: 
#include <linux/kernel.h>
#include <linux/module.h>

int my_module_init(void)
{
	pr_emerg("Hello, world - this is the kernel speaking\n" ) ;
	return 0;
}

MODULE_DESCRIPTION("test driver" ) ;
MODULE_LICENSE("GPL v2" ) ;
MODULE_VERSION("0.1" ) ;

module_init(my_module_init) ;
module_exit(my_module_exit) ;

test_sub.c: 
#include <linux/kernel.h>  
#include <linux/module.h>  
	
void my_module_exit()
{
	pr_emerg("Short is the life of a kernel module\n" ) ;
}
Makefile: 
obj-m = test.o 
test-objs = test_sub.o
all: 
		$(MAKE) -C $(KDIR) M=$(shell pwd) modules

The module is building without any warnings. 

When i execute insmod none of message is appear. It's look like
my_module_init function does not executed at all. 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with module spanning from multiple files
  2012-07-18  7:34 Problem with module spanning from multiple files aleksey
@ 2012-07-18  8:14 ` Philipp Ittershagen
  2012-07-18  8:40   ` aleksey
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Ittershagen @ 2012-07-18  8:14 UTC (permalink / raw)
  To: kernelnewbies

Hi aleksey,

On Wed, Jul 18, 2012 at 9:34 AM, aleksey <lexa@cfotr.com> wrote:
> test.c:
> #include <linux/kernel.h>
> #include <linux/module.h>
>
> int my_module_init(void)
> {
>         pr_emerg("Hello, world - this is the kernel speaking\n" ) ;
>         return 0;
> }
>
> MODULE_DESCRIPTION("test driver" ) ;
> MODULE_LICENSE("GPL v2" ) ;
> MODULE_VERSION("0.1" ) ;
>
> module_init(my_module_init) ;
> module_exit(my_module_exit) ;

this should not compile. How does the compiler know the symbol "my_module_exit"?

Greetings,

  Philipp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with module spanning from multiple files
  2012-07-18  8:14 ` Philipp Ittershagen
@ 2012-07-18  8:40   ` aleksey
  2012-07-18  9:27     ` Philipp Ittershagen
  2012-07-18 14:40     ` Jonathan Neuschäfer
  0 siblings, 2 replies; 6+ messages in thread
From: aleksey @ 2012-07-18  8:40 UTC (permalink / raw)
  To: kernelnewbies

Hi Philipp.


On Wed, 2012-07-18 at 10:14 +0200, Philipp Ittershagen wrote:
> Hi aleksey,
> 
> On Wed, Jul 18, 2012 at 9:34 AM, aleksey <lexa@cfotr.com> wrote:
> > test.c:
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> >
> > int my_module_init(void)
> > {
> >         pr_emerg("Hello, world - this is the kernel speaking\n" ) ;
> >         return 0;
> > }
> >
> > MODULE_DESCRIPTION("test driver" ) ;
> > MODULE_LICENSE("GPL v2" ) ;
> > MODULE_VERSION("0.1" ) ;
> >
> > module_init(my_module_init) ;
> > module_exit(my_module_exit) ;
> 
> this should not compile. How does the compiler know the symbol "my_module_exit"?
> 

I'm terribly sorry by this mistake. i rewrite my code, now it look like:
test.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include "test_sub.h"

int my_module_init(void)
{
pr_emerg("Hello, world module is loading\n");
print_message();
return 0;
}

void my_module_exit(void)
{
pr_emerg("Short is the life of a kernel module\n");
}

MODULE_DESCRIPTION("test driver");
MODULE_LICENSE("GPL v2");
MODULE_VERSION("0.1");

module_init(my_module_init);
module_exit(my_module_exit);

test_sub.h:

void print_message(void);

test_sub.c:

#include <linux/kernel.h>  
#include <linux/module.h>  

void print_message(void)
{
pr_emerg("This is the message from kernel module\n");
}

Makefile: 

obj-m = test.o 
test-objs = test_sub.o
all: 
                $(MAKE) -C $(KDIR) M=$(shell pwd) modules


But the problem is stay. i don't receive any message on module load.

> Greetings,
> 
>   Philipp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with module spanning from multiple files
  2012-07-18  8:40   ` aleksey
@ 2012-07-18  9:27     ` Philipp Ittershagen
  2012-07-18  9:40       ` aleksey
  2012-07-18 14:40     ` Jonathan Neuschäfer
  1 sibling, 1 reply; 6+ messages in thread
From: Philipp Ittershagen @ 2012-07-18  9:27 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Jul 18, 2012 at 10:40 AM, aleksey <lexa@cfotr.com> wrote:
> obj-m = test.o
> test-objs = test_sub.o
> all:
>                 $(MAKE) -C $(KDIR) M=$(shell pwd) modules
>
>
> But the problem is stay. i don't receive any message on module load.

Apparently, the problem is the name of your obj-m target and the name
of the other object which should be build. This worked for me:


obj-m += mytest.o

mytest-objs += test.o test_sub.o


Your kernel module will then be called mytest.ko and consists of
test.o and test_sub.o

Greetings,

  Philipp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with module spanning from multiple files
  2012-07-18  9:27     ` Philipp Ittershagen
@ 2012-07-18  9:40       ` aleksey
  0 siblings, 0 replies; 6+ messages in thread
From: aleksey @ 2012-07-18  9:40 UTC (permalink / raw)
  To: kernelnewbies

On Wed, 2012-07-18 at 11:27 +0200, Philipp Ittershagen wrote:
> On Wed, Jul 18, 2012 at 10:40 AM, aleksey <lexa@cfotr.com> wrote:
> > obj-m = test.o
> > test-objs = test_sub.o
> > all:
> >                 $(MAKE) -C $(KDIR) M=$(shell pwd) modules
> >
> >
> > But the problem is stay. i don't receive any message on module load.
> 
> Apparently, the problem is the name of your obj-m target and the name
> of the other object which should be build. This worked for me:
> 
> 
> obj-m += mytest.o
> 
> mytest-objs += test.o test_sub.o
> 
> 
> Your kernel module will then be called mytest.ko and consists of
> test.o and test_sub.o
> 

Thank you. your advice helped me. I will read documentation more
carefully, i promise.

> Greetings,
> 
>   Philipp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with module spanning from multiple files
  2012-07-18  8:40   ` aleksey
  2012-07-18  9:27     ` Philipp Ittershagen
@ 2012-07-18 14:40     ` Jonathan Neuschäfer
  1 sibling, 0 replies; 6+ messages in thread
From: Jonathan Neuschäfer @ 2012-07-18 14:40 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Jul 18, 2012 at 12:40:52PM +0400, aleksey wrote:
> int my_module_init(void)
> {
> pr_emerg("Hello, world module is loading\n");
> print_message();
> return 0;
> }

Do you get the "Hello, world" message?


Jonathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-07-18 14:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18  7:34 Problem with module spanning from multiple files aleksey
2012-07-18  8:14 ` Philipp Ittershagen
2012-07-18  8:40   ` aleksey
2012-07-18  9:27     ` Philipp Ittershagen
2012-07-18  9:40       ` aleksey
2012-07-18 14:40     ` Jonathan Neuschäfer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.