未知符号__class_create(ERR 0) [英] unknown symbol __class_create (err 0)
问题描述
这可能是一个愚蠢的问题,但是我看了好几个小时在线,无法找到答案...
我正在写一个内核模块也创建了一个字符设备。它编译没有错误和警告,但是当我尝试须藤insmod的my_mod.ko
我得到:
insmod的:错误插入'my_mod.ko:在模块-1未知符号
当我尝试看看的dmesg
我见:
my_mod:未知符号__class_create(ERR 0)
my_mod:未知符号device_create_file(ERR 0)
my_mod:未知符号device_create(ERR 0)
我猜,我错过了一个包含
,但我不能找到它......
在包括需要什么样的?
我的,包括目前:
的#include< Linux的/ - module.h中GT;
#包括LT&;的Linux / kernel.h>
#包括LT&; Linux的/ ip.h>
#包括LT&; Linux的/ netfilter.h中>
#包括LT&; Linux的/ netfilter_ipv4.h>
#包括LT&; Linux的/ cdev.h>
#包括LT&; Linux的/ fs.h文件>
函数的 __ class_create 只对GPL模块(与 EXPORT_SYMBOL_GPL
导出)导出。所以,你需要使用具有 MODULE_LICENSE
宏GPL许可,以使用该功能。同样适用于其它功能。
这应该做的伎俩:
MODULE_LICENSE(GPL);
要了解什么是出口,看看这里。基本上,动态模块不访问的变量和函数内核和内核需要指定什么出口,以使访问。这是 EXPORT_SYMBOL
和 EXPORT_SYMBOL_GPL
宏,这是到处被使用的目的。
和之间的差异 EXPORT_SYMBOL
和 EXPORT_SYMBOL_GPL
的是,后者只显示功能或模块变量是GPL许可。
This is probably a stupid question, but I looked for hours online and couldn't find an answer...
I'm writing a kernel module that also creates a character device. It compiles with no errors and warnings but when I try sudo insmod my_mod.ko
I get:
insmod: error inserting 'my_mod.ko': -1 Unknown symbol in module
and when I try to look at dmesg
I see:
my_mod: Unknown symbol __class_create (err 0)
my_mod: Unknown symbol device_create_file (err 0)
my_mod: Unknown symbol device_create (err 0)
I'm guessing that I missed an include
but I can't find which...
What are the includes needed?
My includes are currently:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/cdev.h>
#include <linux/fs.h>
The function __class_create is exported only for GPL modules (exported with EXPORT_SYMBOL_GPL
). So, you need to use a GPL license with MODULE_LICENSE
macro to make use of that function. Same goes for other functions as well.
This should do the trick:
MODULE_LICENSE("GPL");
To learn about what exporting is, take a look at here. Basically, dynamic modules do not have access to variables and functions in kernel, and kernel needs to specify what to export, to enable access. That's the purpose of EXPORT_SYMBOL
and EXPORT_SYMBOL_GPL
macros, which are used everywhere.
And the difference between EXPORT_SYMBOL
and EXPORT_SYMBOL_GPL
is that the latter only reveals the function or the variable if the module is GPL licensed.
这篇关于未知符号__class_create(ERR 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!