【问题标题】:Adding and compiling new code in the linux kernel在 linux 内核中添加和编译新代码
【发布时间】:2016-10-08 15:29:24
【问题描述】:

这听起来像是一个非常菜鸟的问题。 我正在尝试在 linux 内核中实现基于 UDP 的协议。我是按照 UDPLite 协议实现作为参考的。

第一步

我在 net/ipv4/ 中创建了一个 new_protocol.c
这个文件有一个功能

void _init protocol_init(void){*这里的代码*}

我也用过

#include "udp_impl.h"

在这个文件中,因为我使用了 UDP 协议中的一些函数

第 2 步

我修改了文件 net/ipv4/udp_impl.h 以包含 net/new_protocol.h

第 3 步

我创建了文件 include/net/new_protocol.h 我在其中定义了函数

void protocol_init(void);

第四步

最后,我调用了 net/ipv4/af_inet.c 中的函数。另外,我在此文件中为 net/new_protocol.h

提供了一个包含语句

现在,当我尝试构建内核时,我收到一条错误消息

对 `protocol_init()' 的未定义引用

我在这里缺少什么?我包含头文件的方式不正确吗?我需要在 makefile 中包含一些信息来获取新的 net/ipv4/protocol.c 吗?

【问题讨论】:

  • 旁注:如果您在这里没有得到好的答案;我建议确定一些 linux 内核邮件列表或论坛。

标签: compilation header kernel


【解决方案1】:

我是否需要在 makefile 中包含一些信息才能获取新的net/ipv4/protocol.c

是的,你需要。内核构建系统不会自动检测源文件,它们都应该在适当的Makefile 中明确列出。在您的情况下,您需要修改net/ipv4/Makefile

用于内核构建的 Makefile 在文件 Documentation/kbuild/makefiles.txt 中描述。

【讨论】:

    【解决方案2】:

    我只需要在net/ipv4/的makefile中添加protocol.o

    【讨论】:

      猜你喜欢
      • 2011-07-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 1970-01-01
      • 2021-02-03
      相关资源
      最近更新 更多