【问题标题】:How to add new source files to the glibc makefile?如何将新的源文件添加到 glibc makefile?
【发布时间】:2018-11-17 19:32:54
【问题描述】:

最近我对学习 C 的堆管理(malloc 模块)产生了兴趣。我想将 malloc 源文件(例如 malloc.c、arena.c)分解为更小的文件,以便我更容易阅读和学习。我正在使用 glibc 2.23 并按照 wiki 上的说明在 Ubuntu 14.04 上成功地在本地(在单独的“构建”文件夹中)构建它。

作为我最初的尝试,我将 __malloc_assert 放入文件 massert.hmassert.c 但后来意识到 我不知道如何将它们添加到 makefile 中以便它们可以被编译和链接强>。

由于我将__malloc_assert 移出malloc.c,再次运行make 时出现链接错误,这是意料之中的:

/home/mvs/git/glibc/build/libc_pic.os: In function `detach_arena':
/home/mvs/git/glibc/malloc/arena.c:629: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/build/libc_pic.os: In function `mremap_chunk':
/home/mvs/git/glibc/malloc/malloc.c:2832: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2813: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2812: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2830: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/build/libc_pic.os:/home/mvs/git/glibc/malloc/malloc.c:2776: more undefined references to `__malloc_assert' follow

我想我应该看看 malloc/malloc.c 在 makefile 中是如何使用的,但我找不到它的使用位置。我主要看以下文件:

  • glibc/Makeconfig
  • glibc/Makefile
  • glibc/规则
  • glibc/malloc/Makefile

或者,我在libc-help mailing list 上搜索了makefile 并查看了所有结果,但没有找到与我想要的匹配的结果。其中两个线程,"glibc + add new function""Adding a function to glibc?",正在讨论向库中添加一个新函数,这不是我的情况(我不是添加新函数,只是重构代码)。

我是 makefile 系统的新手,仍在阅读 GNU makefile 手册,但认为在这里发送电子邮件可能会让我更快地摆脱困境。

谢谢!

【问题讨论】:

    标签: c makefile gnu glibc


    【解决方案1】:

    您需要将massert(不是massert.c)添加到malloc/Makefile 中的routines 变量中。

    有几个这样的变量:routines 代表 libc 它自己,但也有 libm-routines 代表 libm,等等。

    默认情况下,这些源文件是为所有变体构建的:静态(.o)、共享(.os)、分析(.op,但默认情况下禁用分析构建)。一些特殊功能仅适用于静态构建(.oS,它们进入libc_nonshared.a)并且也在static-only-routines 中列出。可以使用 elide-routines.os 变量排除特定的构建目标。

    【讨论】:

    • 创造奇迹!
    猜你喜欢
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多