如何防止“错误:‘符号’”此处未声明”尽管 Linux 内核模块中有 EXPORT_SYMBOL ?
当我收到此错误时,我正在将一些驱动程序嵌入到 Linux 内核中(我正在板文件中添加设备并注册它):
error: 'kxtf9_get_slave_descr' undeclared here (not in a function)
我在驱动程序文件中找到了上面的函数,
struct ext_slave_descr *kxtf9_get_slave_descr(void)
{
return &kxtf9_descr;
}
EXPORT_SYMBOL(kxtf9_get_slave_descr);
它不应该通过 EXPORT_SYMBOL 使其“可见”吗? ? 包含上面代码的C文件没有头文件(不是我写的,我只是找到的这里 他们说它已经过测试,所以我假设不需要标头?
其余代码可以完美编译(因此它“看到”文件夹中的代码),并且包含上述代码的文件也可以编译!
I'm embedding some driver into a Linux kernel when I get this error (I'm adding the device in the board file and registering it):
error: 'kxtf9_get_slave_descr' undeclared here (not in a function)
I located the function above in a driver file
struct ext_slave_descr *kxtf9_get_slave_descr(void)
{
return &kxtf9_descr;
}
EXPORT_SYMBOL(kxtf9_get_slave_descr);
Shouldn't it made "visible" by EXPORT_SYMBOL?
The C file containing the code above has no header file (I didn't write it, I just found it here and I'm implementing. They say it's tested so I assume an header is not needed?
The rest of the code compiles perfectly (so it "sees" the code in the folder), and the file containing the code above compiles as well!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EXPORT_SYMBOL
导出动态链接的符号。您遇到的不是链接错误,而是由于缺少函数声明而导致的编译错误。您必须为 C 文件编写一个头文件并包含该头文件,或者将函数声明为您正在编译的 C 文件。选项 1:
kxtf9.h:
your_file.c:
选项 2:
your_file.c:
另请注意文件 kxtf9.c 中的
EXPORT_SYMBOL
周围有#ifdef __KERNEL__
,因此您必须正确设置构建环境(Makefile) - 否则您将收到链接错误。EXPORT_SYMBOL
exports the symbol for dynamic linking. What you have is not a linking error but a compilation error due to a missing function declaration. You have to either write a header file for the C file and include that header file, or you declare the function the C file you're compiling.Option 1:
kxtf9.h:
your_file.c:
Option 2:
your_file.c:
Also note that the
EXPORT_SYMBOL
in the file kxtf9.c has#ifdef __KERNEL__
around it, so you have to have set up your build environment (Makefile) correctly - otherwise you'll get a link error.