如何在一个Linux内核模块中定义一个函数并在另一个Linux内核模块中使用它?
问题描述:
我为内核开发了两个简单的模块.现在,我想在一个模块中定义一个函数,然后在另一个模块中使用它.
I developed two simple modules to the kernel. Now i want to define a function in one module and after that use it in the other.
我该怎么做?
只需在另一个模块中定义函数和调用方就可以了吗?
Just define the function and caller in the other module without problems?
答
在module1.c
中定义它:
#include <linux/module.h>
int fun(void);
EXPORT_SYMBOL(fun);
int fun(void)
{
/* ... */
}
并在module2.c
中使用它:
extern int fun(void);