向内核中加入C文件后。假设想编译进内核须要改动当前文件夹下的Kconfig文件和Makefile文件。
如:加入一个test.c文件到driver文件夹下,则须要改动Kconfig文件:
config MY_TEST tristate "MY_TEST file " depends on I2C ---help--- This is test file about kernel
相同改动Makefile加入一行:
obj-$(CONFIG_MY_TEST) += test.o这样运行make menuconfig 能够看到MY_TEST file这一行,有三种状态:编译进内核,编译成模块,或者不编译。
曾经一直以为Kconfig文件改动没有限制,今天编译内核时。没有注意加入位子,随便找了个地方将新文件的配置选项加入进去,编译的时候报错例如以下:
clk-composite.c:(.text+0x22f25c): undefined reference to `foreground_sdc_select' clk-composite.c:(.text+0x22f274): undefined reference to `bg_overlay_sdc_select' drivers/built-in.o: In function `stop_preview': clk-composite.c:(.text+0x22f2e4): undefined reference to `foreground_sdc_deselect' clk-composite.c:(.text+0x22f2f0): undefined reference to `bg_overlay_sdc_deselect' drivers/built-in.o: In function `mxc_v4l_open': clk-composite.c:(.text+0x22ff28): undefined reference to `csi_enc_select' clk-composite.c:(.text+0x22ff54): undefined reference to `prp_enc_select'经过网行一番查找,得知典型的undefined reference错误,由于在链接时发现找不到某个函数的实现文件。或者说编译顺序有错误。
也就是该c文件调用了其它地方的函数,可是在调用的文件之前编译了。可定找不到将要调用的函数,所以报错了。
详解见:http://www.educity.cn/linux/1241992.html
所以在Kconfig中加入代码须要讲究位子,最好加入在代码功能相近的文件附近。