zoukankan      html  css  js  c++  java
  • 编译3.10内核 出现错误 “undefined reference to...." 解决方法

    向内核中加入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中加入代码须要讲究位子,最好加入在代码功能相近的文件附近。

  • 相关阅读:
    Python3标准库:copy复制对象
    Python3标准库:weakref对象的非永久引用
    Python3标准库:queue线程安全的FIFO实现
    Python3标准库:bisect维护有序列表
    Python3标准库:struct二进制数据结构
    Python3标准库:heapq堆排序算法
    Python3标准库:array数组
    Python3标准库:collections容器数据类型
    20-如何运行容器?
    19-Docker 镜像小结
  • 原文地址:https://www.cnblogs.com/llguanli/p/8583347.html
Copyright © 2011-2022 走看看