ELF:链接:为什么我在 .so 文件中得到未定义的引用

发布于 2024-08-29 03:48:36 字数 1047 浏览 2 评论 0原文

我正在尝试针对 wxWidgets 构建一个程序,但出现链接器错误。我想真正理解这意味着什么。错误是:

/usr/lib/libwx_baseu-2.8.so: undefined reference to `std::ctype<char>::_M_widen_init() const@GLIBCXX_3.4.11'

我不明白为什么错误出现在 libwx_baseu-2.8.so 处。我认为 .so 文件已解析所有符号,这与仍然需要链接的 .o 文件相反。

当我 ldd .so 时,我可以解析它的所有链接库,因此没有问题:

$ ldd /usr/lib/libwx_baseu-2.8.so
 linux-gate.so.1 =>  (0x00476000)
 libz.so.1 => /lib/libz.so.1 (0x00d9c000)
 libdl.so.2 => /lib/libdl.so.2 (0x002a8000)
 libm.so.6 => /lib/libm.so.6 (0x00759000)
 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x002ad000)
 libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0068d000)
 libpthread.so.0 => /lib/libpthread.so.0 (0x006f0000)
 libc.so.6 => /lib/libc.so.6 (0x00477000)
 /lib/ld-linux.so.2 (0x007f6000)

这是否意味着 .so > 文件未正确编译(在这种情况下,这是我的发行包中的错误),或者这是否意味着我的特定程序的链接器命令行上缺少库?

另外,您知道如何获取 ELF 文件中未定义符号的列表吗?我尝试了 readelf -s 但找不到丢失的符号。

谢谢。

米尔德里德

I'm trying to build a program against wxWidgets, and I get a linker error. I'd like to really understand what it means. The error is:

/usr/lib/libwx_baseu-2.8.so: undefined reference to `std::ctype<char>::_M_widen_init() const@GLIBCXX_3.4.11'

What I don't understand is why the error is at libwx_baseu-2.8.so. I thought that .so files had all its symbols resolved, contrary to .o files that still need linking.

When I ldd the .so, I get can resolve all its linked libraries, so there is no problem there:

$ ldd /usr/lib/libwx_baseu-2.8.so
 linux-gate.so.1 =>  (0x00476000)
 libz.so.1 => /lib/libz.so.1 (0x00d9c000)
 libdl.so.2 => /lib/libdl.so.2 (0x002a8000)
 libm.so.6 => /lib/libm.so.6 (0x00759000)
 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x002ad000)
 libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0068d000)
 libpthread.so.0 => /lib/libpthread.so.0 (0x006f0000)
 libc.so.6 => /lib/libc.so.6 (0x00477000)
 /lib/ld-linux.so.2 (0x007f6000)

Does it means that the .so file was not compiled correctly (in that case, it's a bug in my distribution package) or does it means that there are missing libraries on the linker command line for my particular program?

Additionally, do you know how I can get a list on undefined symbols in an ELF file. I tried readelf -s but I can't find the missing symbol.

Thank you.

Mildred

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

遗忘曾经 2024-09-05 03:48:36

我认为 .so 文件已解析所有符号,与仍需要链接的 .o 文件相反。

共享库可能不完整,但这没关系。

你知道如何获取 ELF 文件中未定义符号的列表

使用

nm -C -u libwx_baseu-2.8.so

I thought that .so files had all its symbols resolved, contrary to .o files that still need linking.

Shared libraries can be incomplete, that is OK.

do you know how I can get a list on undefined symbols in an ELF file

Use

nm -C -u libwx_baseu-2.8.so

金兰素衣 2024-09-05 03:48:36

我认为您在链接程序时没有链接到某些库。

在程序中链接到 .so 中链接到的所有共享库

如果 .so 链接到某些静态库 - 如果在 .so 中找到所有需要的符号,则程序中不需要链接到它们

您应该 使用 nm linux 命令查看目标文件、库或二进制文件中的符号

编辑
您的具体问题可以在这里描述: http://old.nabble.com/-Bug-49433--gcc4.4,-NEW:-gcc4.4-misses-std: :endl-implementation-at--O2%2B-td22836171.html

I think you don't link to some of the libraries when linking your program.

You should link in your program to all shared libraries you link to in your .so

If the .so is linked to some static libraries - it's not required in the program to link to them if all needed symbols are found in the .so

You may use nm linux command to see the symbols in object file, library or binary

Edit
Your particular problem can be described here: http://old.nabble.com/-Bug-49433--gcc4.4,-NEW:-gcc4.4-misses-std::endl-implementation-at--O2%2B-td22836171.html

梦回梦里 2024-09-05 03:48:36

当您将一个共享库链接到其他共享库时(例如将 libwx_baseu-2.8.so 链接到 libstdc++.so),链接器会记录 libwx_baseu< 使用的版本化符号/code> 并由 libstdc++ 提供。

如果在运行时您使用不同的 libstdc++ 副本(不提供相同版本符号的副本),您会收到(动态)喜欢错误,并且程序根本无法运行(这比稍后的“神秘”崩溃更好)。

但这里发生的情况是,您尝试链接可执行文件,这意味着(静态)链接器想要找到运行时所需的所有符号。同样,您将可执行文件链接到不同的(较旧的)libstdc++.so,因此链接失败。

通常有两个根本原因:
- 您可以在不同的系统(具有较新版本的 GCC)上链接 libwx_baseu-2.8.so,并将其复制到当前系统,或者
- 您已将 libwx_baseu-2.8.so 与同一系统上的较新 GCC 链接,但现在尝试将可执行文件与较旧的 GCC 链接。

When you link a shared library against other shared libraries (e.g. link libwx_baseu-2.8.so against libstdc++.so), the linker records versioned symbols used by libwx_baseu and provided by libstdc++.

If at runtime you use a different copy of libstdc++ (one which doesn't provide the same versioned symbol(s)), you get a (dynamic) liking error and the program doesn't run at all (this is preferable to a "mystery" crash later on).

But what's happening here is that you try to link an executable, which means the (static) linker wants to find all symbols which will be required at runtime. Again, you are linking the executable against a different (older) libstdc++.so, and so the linking fails.

There are two usual root causes:
- either you linked libwx_baseu-2.8.so on a different system (one with newer version of GCC), and copied it to the current system, or
- you've linked libwx_baseu-2.8.so with a newer GCC on the same system, but now are trying to link the executable with an older GCC.

就像说晚安 2024-09-05 03:48:36

尝试:放置 -fno-inline
在 Makefile 中的标志中。基本上 g++4.4 没有它就会出现问题。尝试放置它或删除 -O 选项。它解决了我遇到的同样的问题。

Try : putting -fno-inline
in your flags in Makefile. Basically g++4.4 is having issues without it. Try to put it OR remove the -O option. It solved the same problem I had.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文