如何防止“错误:此处未声明'符号'";尽管在Linux内核模块中使用EXPORT_SYMBOL? [英] How to prevent "error: 'symbol' undeclared here" despite EXPORT_SYMBOL in a Linux kernel module?

查看:142
本文介绍了如何防止“错误:此处未声明'符号'";尽管在Linux内核模块中使用EXPORT_SYMBOL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出现此错误时,我正在将一些驱动程序嵌入Linux内核中(我将设备添加到了board文件中并进行了注册):

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);

它不应该被EXPORT_SYMBOL设为可见"吗? 包含上面代码的C文件没有头文件(我没有写它,我只是发现它

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!

推荐答案

EXPORT_SYMBOL导出符号以进行动态链接.您所拥有的不是链接错误,而是由于缺少函数声明而导致的编译错误.您必须为C文件编写一个头文件并包含该头文件,或者将函数声明为您要编译的C文件.

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.

选项1:

kxtf9.h:

#ifndef KXTF9_H
#define KXTF9_H

struct ext_slave_descr *kxtf9_get_slave_descr(void);

#endif

your_file.c:

your_file.c:

#include "kxtf9.h"
/* your code where you use the function ... */

选项2:

your_file.c:

your_file.c:

struct ext_slave_descr *kxtf9_get_slave_descr(void);
/* your code where you use the function ... */

还请注意,文件kxtf9.c中的EXPORT_SYMBOL周围带有#ifdef __KERNEL__,因此您必须正确设置构建环境(Makefile)-否则会出现链接错误.

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.

这篇关于如何防止“错误:此处未声明'符号'";尽管在Linux内核模块中使用EXPORT_SYMBOL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆