Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent "error: 'symbol' undeclared here" despite EXPORT_SYMBOL in a Linux kernel module?

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!

like image 820
stef Avatar asked Jul 12 '11 20:07

stef


People also ask

What is EXPORT_SYMBOL in Linux kernel?

EXPORT_SYMBOL() is a macro the Linux kernel headers define. It has not much in common with extern. It tells the kbuild mechanism that the symbol referred to should be part of the global list of kernel symbols. That, in turn allows kernel modules to access them.

What is module Symvers file?

During a kernel build, a file named Module. symvers will be generated. Module. symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored.


1 Answers

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:

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

Option 2:

your_file.c:

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

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.

like image 174
Antti Avatar answered Sep 21 '22 23:09

Antti