与 libc 的链接混乱

发布于 2024-08-11 06:50:07 字数 319 浏览 9 评论 0原文

我有一个库编译成 .a 文件,链接到我的应用程序。 (iphone,使用 Xcode 开发)

一切似乎都很好,链接似乎成功,但是当我运行程序时它崩溃了。崩溃点在于静态链接库中的 memcmp() 调用。调试器显示名称中带有“dyld”的所有类型的内容,因此似乎无论出于何种原因它都无法解析 memcmp,开始寻找动态库,然后失败。

AFAIK memcmp 在 libc 中,所以应该不是问题。 (也尝试将 -lc 传递给链接器,但它没有帮助,正如我预期的那样)

那么它应该如何工作?为什么静态链接库不能使用 libc 中的任何内容?我应该如何编译它?

谢谢

I have a library compiled into a .a file, linked against my application. (iphone, developing with Xcode)

Everything seems to be fine, linking seems to succeed, but when I run the program it crashes. The point of crash is at a memcmp() call in the statically linked library. The debugger shows all kind of stuff called with "dyld" in their names, so it seems that for whatever reason it can not resolve memcmp, starts looking for dynamic libraries, then fails.

AFAIK memcmp is in libc, so should not be a problem. (tried also passing -lc to the linker, and it did not help, just as I expected)

So how it is supposed to work? Why can't a statically linked library use anything from libc? How should I compile it?

Thank you

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

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

发布评论

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

评论(2

白芷 2024-08-18 06:50:08

libc 显然是在您的平台上动态链接的。在运行时无法找到匹配的版本来满足链接时生成的依赖关系。

除了文件系统损坏或在动态链接发生之​​前调用 chroot(这似乎不太可能)之外,我无法解释这是如何发生的。

libc is apparently dynamically linked on your platform. A matching version cannot be found at runtime to satisfy the dependency generated at link time.

I can't explain how this would happen other than filesystem corruption or calling chroot before the dynamic linking happens (which would seem unlikely).

韶华倾负 2024-08-18 06:50:08

如果我分享问题所在,也许有人会发现它很有用:

该库不是为与主程序相同的操作系统版本编译的,因此它期望一个与运行时发现的不同的 libc。

Perhaps someone will find it useful if I share what the problem was:

The library was not compiled for the same OS version as the main program, so it was expecting a different libc than what it found when running.

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