簡體   English   中英

盡管 Linux kernel 模塊中有 EXPORT_SYMBOL,如何防止“錯誤:此處未聲明'符號'”?

[英]How to prevent “error: 'symbol' undeclared here” despite EXPORT_SYMBOL in a Linux kernel module?

當我收到此錯誤時,我將一些驅動程序嵌入到 Linux kernel 中(我在板文件中添加設備並注冊它):

error: 'kxtf9_get_slave_descr' undeclared here (not in a function)

我在驅動程序文件中找到了上面的 function

struct ext_slave_descr *kxtf9_get_slave_descr(void)
{
    return &kxtf9_descr;
}
EXPORT_SYMBOL(kxtf9_get_slave_descr);

EXPORT_SYMBOL 不應該讓它“可見”嗎? 包含上述代碼的 C 文件沒有 header 文件(我沒有寫它,我只是在這里找到它並且我正在實施。他們說它已經過測試所以我假設不需要 Z099FB995346F33C749F6E40EDB0?

代碼的 rest 可以完美編譯(因此它“看到”文件夾中的代碼),包含上述代碼的文件也可以編譯!

EXPORT_SYMBOL導出動態鏈接的符號。 您所擁有的不是鏈接錯誤,而是由於缺少 function 聲明而導致的編譯錯誤。 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:

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

選項 2:

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) - 否則會出現鏈接錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM