【发布时间】:2018-11-17 19:32:54
【问题描述】:
最近我对学习 C 的堆管理(malloc 模块)产生了兴趣。我想将 malloc 源文件(例如 malloc.c、arena.c)分解为更小的文件,以便我更容易阅读和学习。我正在使用 glibc 2.23 并按照 wiki 上的说明在 Ubuntu 14.04 上成功地在本地(在单独的“构建”文件夹中)构建它。
作为我最初的尝试,我将 __malloc_assert 放入文件 massert.h 和 massert.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 手册,但认为在这里发送电子邮件可能会让我更快地摆脱困境。
谢谢!
【问题讨论】: