The Linux kernel driver compiles multiple C files into a KO file--each C file has Module_init and Module_exit

Source: Internet
Author: User
Tags function prototype

Take two C files as an example:

The adc_device.c, Adc_ driver.c, which should have been compiled separately into adc_Device.ko and adc_Driver.ko, are compiled into a KO file!

Method of Adoption:

First step, modify C file
1, remove adc_device.c file module_init (XXX), Module_exit (yyy) in the XXX, yyy function prototype keyword static
2, Logout adc_device.c file module_init (XXX), module_exit (yyy) function
3. Add the above xxx, yyy functions declared with the keyword extern in the adc_driver.c file.
4, in adc_driver.c file Module_init (mmm), Module_exit (nnn) in the MMM, NNN function prototype appropriate place to call XXX, yyy function
Note: When compiling multiple C files into a. ko file, the module_init and module_exit in the C file will prompt for redefinition,
So a KO inside can only have a module_init and a module_exit!

Step two, write the Makefile file (Key section)

Obj-m + = ADC.O
ADC-OBJS: = ADC_DEVICE.O adc_driver.o

In this way, the adc_device.c, ADC_DRIVER.C, which should have been compiled separately into Adc_device.ko and Adc_driver.ko

Compile into a Adc.ko file!

The Linux kernel driver compiles multiple C files into a KO file--each C file has Module_init and Module_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.