linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Modules Spanning Multiple Files?
@ 2004-02-26  2:57 Vineet Joglekar
  0 siblings, 0 replies; 2+ messages in thread
From: Vineet Joglekar @ 2004-02-26  2:57 UTC (permalink / raw)
  To: linux-c-programming


Hi all,

I am trying to learn to write a kernel module in which functions are present in more than 1 file.

With ref. to the information available on web, the code looks like:

/***************** file 1 *******************/
/* hello2_start.c */

#if defined(CONFIG_MODVERSIONS)  && ! defined(MODVERSIONS)
   #include <linux/modversions.h> /* Will be explained later */
   #define MODVERSIONS
#endif
#include <linux/kernel.h>       /* We're doing kernel work */
#include <linux/module.h>       /* Specifically, a module */

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

/***************** file 1 *******************/
/*  stop.c  */

#if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
   #include <linux/modversions.h> /* Will be explained later */
   #define MODVERSIONS
#endif        
#include <linux/kernel.h>  /* We're doing kernel work */
#include <linux/module.h>  /* Specifically, a module  */
#define __NO_VERSION__     /* It's not THE file of the kernel module */
#include <linux/version.h> /* Not included by module.h because of
	                                      __NO_VERSION__ */
	
void cleanup_module()
{
   printk("<1>Short is the life of a kernel module\n");
}

/********************* Makefile *******************/

CC=gcc
MODCFLAGS = -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes
   	
hello.o:	hello2_start.o hello2_stop.o
	ld -m elf_i386 -r -o hello2.o hello2_start.o hello2_stop.o

start.o:	hello2_start.c
	${CC} ${MODCFLAGS} -c hello2_start.c

stop.o:	hello2_stop.c
	${CC} ${MODCFLAGS} -c hello2_stop.c

/********************* ************************/

when I do make, it doesnt give me any warnings/errors, but when I try to do
insmod -f hello2.o

it gives me error like:
"hello2.o: couldn't find the kernel version the module was compiled for"

What do I do regarding this?

Thanks and regards,

Vineet


_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!

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

* RE: Modules Spanning Multiple Files?
@ 2004-02-26 18:22 Vineet Joglekar
  0 siblings, 0 replies; 2+ messages in thread
From: Vineet Joglekar @ 2004-02-26 18:22 UTC (permalink / raw)
  To: linux-c-programming


Hi all,

the problem is solved. It had to do something with the condition checking for versioning.
the code

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif        

instead of

#if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
   #include <linux/modversions.h> /* Will be explained later */
   #define MODVERSIONS
#endif

helped.

Thanks and regards

Vineet

 --- On Wed 02/25, Vineet Joglekar < vintya@excite.com > wrote:
From: Vineet Joglekar [mailto: vintya@excite.com]
To: linux-c-programming@vger.kernel.org
Date: Wed, 25 Feb 2004 21:57:56 -0500
Subject: Modules Spanning Multiple Files?

Hi all,<br><br>I am trying to learn to write a kernel module in which functions are present in more than 1 file.<br><br>With ref. to the information available on web, the code looks like:<br><br>/***************** file 1 *******************/<br>/* hello2_start.c */<br><br>#if defined(CONFIG_MODVERSIONS)  && ! defined(MODVERSIONS)<br>   #include <linux/modversions.h> /* Will be explained later */<br>   #define MODVERSIONS<br>#endif<br>#include <linux/kernel.h>       /* We're doing kernel work */<br>#include <linux/module.h>       /* Specifically, a module */<br><br>int init_module(void)<br>{<br>  printk("Hello, world - this is the kernel speaking\n");<br>  return 0;<br>}<br><br>/***************** file 1 *******************/<br>/*  stop.c  */<br><br>#if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)<br>   #include <linux/modversions.h> /* Will be explained later */<br>   #define MOD
 VERSIONS<br>#endif        <br>#include <linux/kernel.h>  /* We're doing kernel work */<br>#include <linux/module.h>  /* Specifically, a module  */<br>#define __NO_VERSION__     /* It's not THE file of the kernel module */<br>#include <linux/version.h> /* Not included by module.h because of<br>	                                      __NO_VERSION__ */<br>	<br>void cleanup_module()<br>{<br>   printk("<1>Short is the life of a kernel module\n");<br>}<br><br>/********************* Makefile *******************/<br><br>CC=gcc<br>MODCFLAGS = -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes<br>   	<br>hello.o:	hello2_start.o hello2_stop.o<br>	ld -m elf_i386 -r -o hello2.o hello2_start.o hello2_stop.o<br><br>start.o:	hello2_start.c<br>	${CC} ${MODCFLAGS} -c hello2_start.c<br><br>stop.o:	hello2_stop.c<br>	${CC} ${MODCFLAGS} -c hello2_stop.c<br><br>/********************* 
 ************************/<br><br>when I do make, it doesnt give me any warnings/errors, but when I try to do<br>insmod -f hello2.o<br><br>it gives me error like:<br>"hello2.o: couldn't find the kernel version the module was compiled for"<br><br>What do I do regarding this?<br><br>Thanks and regards,<br><br>Vineet<br><br><br>_______________________________________________<br>Join Excite! - http://www.excite.com<br>The most personalized portal on the Web!<br>

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!

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

end of thread, other threads:[~2004-02-26 18:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-26 18:22 Modules Spanning Multiple Files? Vineet Joglekar
  -- strict thread matches above, loose matches on Subject: below --
2004-02-26  2:57 Vineet Joglekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).