gcc - 对 `dl_iterate_phdr' 的 undefined reference

标签 gcc linker ld

我需要帮助!!我正在尝试构建一个独立的可执行文件,即没有任何动态链接。

我编写了一个小测试程序,为它生成了一个名为 test.o 的可重定位目标文件。当我尝试使用 GNU 链接器构建独立可执行文件时,出现以下错误:

$ld -static -o test test.o/usr/lib/crt1.o/usr/lib/crti.o/usr/lib/libc.a/usr/lib/gcc/i486-linux-gnu/4.4/libgcc .a/usr/lib/gcc/i486-linux-gnu/4.4/libgcc_eh.a
/usr/lib/gcc/i486-linux-gnu/4.4/libgcc_eh.a(unwind-dw2-fde-glibc.o): 在函数 _Unwind_Find_FDE': (.text+0x190b): undefined reference to dl_iterate_phdr'

如何解决 undefined symbol dl_iterate_phdr 。这个符号出现在哪个文件中?

谢谢!!!

编辑1:

以防万一,如果我不是很清楚,我的动机是生成一个独立的可执行文件,即一个可执行文件,它在加载到内存中时完全可以执行,即)所有符号解析和重定位都是由程序链接器本身而不是动态链接器完成的.是否可以生成这样的可执行文件?

最终更新:

现在我得到它直接使用以下命令来遵守 ld :

$ld -static -o test/usr/lib/crt1.o/usr/lib/crti.o/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbeginT.o/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o test.o --start-group/usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc.a/usr/lib/gcc/i486- linux-gnu/4.4.3/libgcc_eh.a/usr/lib/libc.a --end-group

man ld 说 --start-group archives --endgroup 用于解决循环引用!!我还发现符号 dl_iterate_phdr 是在 libc.a 中定义的。

感谢你的帮助!!

最佳答案

When I try to build the standalone executable using GNU linker



别。使用 ld 链接任何用户空间程序通常是一个错误。您的链接行肯定是不正确的。

使用编译器驱动程序为您完成繁重的工作。这应该有效:
gcc -static -o test test.o

I am looking to use ld since I wanted to build a standalone executable



是什么让您相信 GCC 构建的可执行文件不如 ld 构建的可执行文件那么独立?不管它是什么,你都错了:gcc 只是用正确的参数调用 ld

关于gcc - 对 `dl_iterate_phdr' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14324157/

相关文章:

c - 所有 gcc 版本都支持 gcc 的 @file 选项吗?

c++ - 为什么 GCC 拒绝引用 std::optional?

gcc - 为什么 g++ 警告我将枚举值与指定的基础类型进行比较?

c++ - GCC 不链接库。它编译,但生成的库缺少必要的引用

c++ - Premake OpenGL SDK 无法从教程构建项目

ios - 链接器错误 - 尝试链接到 arm,但链接器使用 x86

c - 为什么 GCC 不在此示例中发出警告

c - 链接目标文件,使包含变得多余?

ios - xcodebuild -- iOS -- 链接错误的 dylib

c++ - 如何用二进制文本在 LD 中指定名称?