与 libc 的链接混乱
我有一个库编译成 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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).
如果我分享问题所在,也许有人会发现它很有用:
该库不是为与主程序相同的操作系统版本编译的,因此它期望一个与运行时发现的不同的 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.