A simple question: How to use EXPORT_SYMBOL()

More
17 Apr 2025 07:26 #326509 by RushA
hi,
I have a question in using linuxcnc 2.9.
I want to call the function defined in the other module. In module A, I export a function using EXPROT_SYMBOL(). In module B, I use "extern" to declare the function and call it. However, it always tells me "undefined symbol". How to solve this problem?

Please Log in or Create an account to join the conversation.

More
18 Apr 2025 08:53 #326576 by andypugh
Replied by andypugh on topic A simple question: How to use EXPORT_SYMBOL()
Presumably this is in C?

You may need ti #include A.h in B.c

Please Log in or Create an account to join the conversation.

More
21 Apr 2025 00:55 #326782 by RushA
hi, thanks!
yes, it's C. I did include A.h in B.c, but it doesn't work.

Please Log in or Create an account to join the conversation.

More
21 Apr 2025 18:10 #326824 by andypugh
Replied by andypugh on topic A simple question: How to use EXPORT_SYMBOL()
Maybe both modules also need to include <linux/module.h> ?

lkw.readthedocs.io/en/latest/doc/04_exporting_symbols.html

Please Log in or Create an account to join the conversation.

More
22 Apr 2025 01:25 #326864 by RushA
hi,thanks!
It doesn't work too. However, I find something in rtapi.h file.
I think it is not like the linux kernel modules.

#if !defined(__KERNEL__)
#define MODULE_INFO1(t, a, c) __attribute__((section(".modinfo"))) \
    t rtapi_info_##a = c; EXPORT_SYMBOL(rtapi_info_##a);
#define MODULE_INFO2x(t, a, b, c) MODULE_INFO2(t,a,b,c)
#define MODULE_INFO2(t, a, b, c) __attribute__((section(".modinfo"))) \
    t rtapi_info_##a##_##b = c; EXPORT_SYMBOL(rtapi_info_##a##_##b);
#define MODULE_PARM(v,t) MODULE_INFO2(const char*, type, v, t) MODULE_INFO2(void*, address, v, &v)
#define MODULE_PARM_DESC(v,t) MODULE_INFO2(const char*, description, v, t)
#define MODULE_LICENSE(s) MODULE_INFO1(const char*, license, s)
#define MODULE_AUTHOR(s) MODULE_INFO1(const char*, author, s)
#define MODULE_DESCRIPTION(s) MODULE_INFO1(const char*, description, s)
#define MODULE_SUPPORTED_DEVICE(s) MODULE_INFO1(const char*, supported_device, s)
#define MODULE_DEVICE_TABLE(x,y) MODULE_INFO2(struct rtapi_pci_device_id*, device_table, x, y)
#define MODULE_INFO(x,y) MODULE_INFO2x(char*, x, __LINE__, y)
#define EXPORT_SYMBOL(x) __attribute__((section(".rtapi_export"))) \
    char rtapi_exported_##x = #x;
#define EXPORT_SYMBOL_GPL(x) __attribute__((section(".rtapi_export"))) \
    char rtapi_exported_##x = #x;




 

Please Log in or Create an account to join the conversation.

More
22 Apr 2025 14:59 #326896 by andypugh
Replied by andypugh on topic A simple question: How to use EXPORT_SYMBOL()
Are you #including rtapi.h ?

Thinking about it, you can probably use the buuilt-in EXPORT_SYMBOL in kernel modules (ie, if using RTAI). But in uspace this may be re-defined to be something else. (as suggested by the code you posted)

Please Log in or Create an account to join the conversation.

More
23 Apr 2025 02:39 #326928 by RushA
yes, I include rtapi.h file.

Please Log in or Create an account to join the conversation.

Time to create page: 0.067 seconds
Powered by Kunena Forum