EXPORT_SYMBOL使用 [英] Use of EXPORT_SYMBOL

查看:264
本文介绍了EXPORT_SYMBOL使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我嵌入一些司机到Linux内核中,当我得到这个错误(我将在电路板文件设备并对其进行注册):

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?
包含上述code的C文件没有头文件(我没有写,我只是发现它的here和我实施。他们说这是测试,所以我认为是不是需要一个头?

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?

在code的其余部分完全编译(所以看到code文件夹中),以及含有上述code中的文件编译的!

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 ... */

另外请注意, EXPORT_SYMBOL 在文件kxtf9.c具有 #IFDEF __kernel __ 围绕它,所以你必须已经设置您的构建环境(生成文件)正确的 - 否则你会得到一个链接错误

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.

这篇关于EXPORT_SYMBOL使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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