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

前端 未结 1 962
走了就别回头了
走了就别回头了 2021-01-02 20:04

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_         


        
相关标签:
1条回答
  • 2021-01-02 20:33

    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.

    0 讨论(0)
提交回复
热议问题