共享库中未定义的外部符号

发布于 2024-12-05 12:32:38 字数 342 浏览 1 评论 0原文

我最近在 iOS SDK4.3 的 System.B.dylib 库上运行了 nm -m -p -g,并惊讶地发现很多标记为 的符号>(未定义)(外部)。为什么以及何时将未定义的符号标记为外部?我可以理解标记为“lazy”或“weak”的未定义外部符号,但这些不是。许多pthread_xxx函数都属于这一类。然而,当我链接到这个库时,所有符号都被解析。 pthread_xxx 符号是在 \usr\lib\system 文件夹中的库之一中定义的,因此我假设它们从那里得到满足。在链接过程中它是如何工作的?

I recently ran nm -m -p -g on the System.B.dylib library from the iOS SDK4.3 and was surprised to find a lot of symbols marked (undefined) (external). Why and when would an undefined symbol be marked external? I can understand a undefined external symbol marked lazy or weak but these aren't. Many of the pthread_xxx functions fall in this category. When I link with this library however, all symbols are resolved. The pthread_xxx symbols are defined in one of the libraries in the \usr\lib\system folder so I am assume they are satisfied from there. How does that work during linking?

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

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

发布评论

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

评论(2

踏雪无痕 2024-12-12 12:32:39

我已经有一段时间没有成为 nmld C 编码忍者了,但我认为这仅意味着这个库还链接了其他库。

It's been a while since I was an nm and ld C-coding ninja, but I think this only means that there are other libraries this one links against.

抽个烟儿 2024-12-12 12:32:39

通常这就是动态链接的工作原理。如果您要管理 System.B 的静态存档,您将不会观察到此行为。 System.B.dylib 本身不会做太多事情;除非您将其作为其所使用的函数的动态和静态库集合的一部分。如果您现在尝试编译最终的二进制文件但省略库路径“/usr/lib/system”,那么您的链接器将大喊大叫并退出并显示错误,告诉您它找不到对 pthread_XXX() 的引用(使用上面的示例) )。在二进制文件的最终组装过程中,它需要确保知道所使用的每个函数的位置。

华泰

Usually this is how dynamic linking works. If you were to nm a static archive of System.B, you would not have observed this behavior. The System.B.dylib on it's own would not do much; unless you make it as part of an ensemble set of dynamic and static libraries whose functions it makes use of. If you now try to compile your final binary BUT omit the library path '/usr/lib/system' then you linker will cry foul and exit with an error telling you that it cannot find a reference to pthread_XXX() (using your above example). During the final assembling of the binary, it needs to make sure it knows the location of each and every function used.

HTH

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