Eclipse has a powerful auto-completion function, which is handy when you browse code and edit code. Next I will introduce how to configure eclipse to help us open the Linux driver.
(Note that eclipse is called Eclipse IDE for C/C ++ developers. Instead of Eclipse IDE for Java developers after installing the CDT plug-in ).
1. Create a new C Project. This project is specially designed for drivers.
In the project explorer list on the right, right-click the project you just created and select Properties.
Select C/C ++ General> paths and symbols, select the des tab on the right, and select GNU C
The default include path of the compiler is displayed on the right.
/Path/of/kernel/DIR/include
/Path/of/kernel/DIR/ARCH/ARM/include
(If you are writing an x86 driver, use/path/of/kernel/DIR/ARCH/x86/include)
Select the symbols tab and click Export settings below to export the settings as an XML file.
Open the XML file and add
<Macro> <name >__ kernel __</Name> <value> 1 </value> </macro>
Then we need to add the macro definition in Autoconf. h to eclipse and perform the following steps:
- CD/path/of/kernel/DIR/include/Linux/
- Cat Autoconf. H | grep define | awk '{print "<macro> <Name>" $2 "</Name> <value>" $3 "</value> </macro>"} '> symbol. XML
Open symbol. xml and copy all the content to the end of the XML file </macro>.
Save the file and click Import settings to import the file. (If a parsing error is frequently prompted during import, the XML format is incorrect, make sure to check the error .)
Click OK to exit properties, right-click the project, and select index-> rebuild
However, there is still no way to compile automatically after configuration. You have to use your own makefile for compiling.
Select project properties.
Select C/C ++ build-> makefile generation, and set build direcotry as the makefile location. For example, $ {workspace_loc:/hellodriver }. The hellodriver is the root directory of my project.
Then manually write the MAKEFILE file. And place it in the root directory of the project.
Makefile example
pwd = $(shell pwd)KERNEL_SRC = /lib/modules/$(shell uname -r)/buildobj-m := hello.omodule-objs := hello.oall: $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modulesclean: rm -f *o *~ .*cmd *o *ko *~ .*cmd hello.mod.c
Right-click the project and choose make target> create. In the displayed dialog box, enter target name. The name here is generally the name of the target in your own makefile. In my MAKEFILE file, I generally write all. You can also add clean in the same way.
In this case, you can use eclipse to compile your own driver and use make to automatically compile the driver.