Linux export symbol List Example

Source: Internet
Author: User

-- Modified based on netizens

Module 1 code:

#include<linux/init.h>#include<linux/module.h>MODULE_LICENSE("Dual BSD/GPL");int test_global_value_1 = 0x55;int test_global_value_2 = 0xaa;EXPORT_SYMBOL(test_global_value_1);EXPORT_SYMBOL(test_global_value_2);static int __init symbol_init(void){     printk("<0> symbol_init\n");     return 0; } int add_integar(int a, int b) {     return (a + b); }int sub_integar(int a, int b){    return (a - b);}static void __exit symbol_exit(void){    printk("<0> symbol_exit\n");}EXPORT_SYMBOL(add_integar);EXPORT_SYMBOL(sub_integar);module_init(symbol_init);module_exit(symbol_exit);

Module 2 code:

#include<linux/module.h>#include<linux/init.h>extern int add_integar(int, int);extern int sub_integar(int, int);extern int test_global_value_1;extern int test_global_value_2;MODULE_LICENSE("GPL");static int __init use_symbol_init(void){   printk("test_global_value_1 = %x\n", test_global_value_1);printk("test_global_value_2 = %x\n", test_global_value_2);printk("<0> use_symbol_init");printk("<0> 1+2 = %d\n",add_integar(1,2));printk("<0> 3-2 = %d\n",sub_integar(3,2));return 0;}static void __exit use_symbol_exit(void){   printk("<0> Module exit!\n");}module_init(use_symbol_init);module_exit(use_symbol_exit);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.