|
在看linux设备驱动这本书的模块间通信这一章,想试试它export symbol的例子,但是make file 不知道怎么写啊,请大虾指点一下。
export.c
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/config.h> /* retrieve the CONFIG_* macros */
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
# define MODVERSIONS
#endif
#if defined(MODVERSIONS) && !defined(__GENKSYMS__)
# include <linux/modversions.h>
# include "export.ver" /* redefine "export_function" to include CRC */
#endif
int export_function(int a, int b);
EXPORT_SYMBOL(export_function);
int export_init(void)
{
return 0;
}
void export_cleanup(void)
{
}
int export_function(int a, int b)
{return a+b;}
module_init(export_init);
module_exit(export_cleanup);
import.c
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
/*
* Use versioning if needed
*/
#include <linux/config.h> /* retrieve the CONFIG_* macros */
#ifdef CONFIG_MODVERSIONS
# undef MODVERSIONS /* it might be defined */
# define MODVERSIONS
#endif
#ifdef MODVERSIONS
# include <linux/modversions.h>
# include "export.ver"
#endif
#include <linux/module.h>
#include <linux/kernel.h>
extern int export_function(int, int);
int import_init(void)
{
int i = export_function(2,2);
printk("import: my mate tells that 2+2 = %i\n",i);
return 0;
}
void import_cleanup(void)
{
}
module_init(import_init);
module_exit(import_cleanup);
目的就是让import调用export模块的那个export_function函数。 |
|