Mac OS X:通过添加函数来扩展共享库

发布于 2024-11-18 01:57:57 字数 409 浏览 1 评论 0原文

我想通过添加函数来扩展 Mac OS X 上的共享 c 库 (dylib)。让我们调用函数 const char *get_string(void)。我的方法如下:

我创建了一个包含 get_string(void) 函数的新共享库,并且喜欢它来对抗我想要扩展的库。可以说是一个库包装。到目前为止,一切都很好。下一步是将应用程序链接到我的新扩展库,但问题是扩展库仅导出符号 _get_string 而不是原始库的那些符号。这就是为什么链接“扩展”库(而不是原始库)会产生大量未解析的符号警告/错误。

有没有办法导出原始库的所有这些符号(有很多)或者是否有更好的方法来解决问题。基本上我只是想扩展现有的库。顺便说一句,我可以访问原始库的源代码,但我不能只是重新编译它。

提前致谢!

I would like to extend a shared c library (dylib) on Mac OS X by adding a function. Let's call the function const char *get_string(void). Here is my approach:

I created a new shared library containing the get_string(void) function and liked it against the library I wanted to extend. A library wrapper so to speak. So far so good. The next step would be to link an application against my new extended library but the problem is that the extended library does only export the symbol _get_string but not those symbols of the original library. That's why linking against the "extended" library (instead of the original library) produces a lot of unresolved symbol warnings/error.

Is there any way to export all those symbols of the original library (there are a lot) or is there a better approach to solve the problem. Basically I just want to extend an existing library. BTW I have access to the original library's source but I can't just recompile it.

Thanks in advance!

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

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

发布评论

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

评论(1

浅紫色的梦幻 2024-11-25 01:57:57

ld 这个选项怎么样:

     -reexport-lx
             This is the same as the -lx but specifies that the all symbols in library x should
             be available to clients linking to the library being created.  This was previously
             done with a separate -sub_library option.

How about this option to ld:

     -reexport-lx
             This is the same as the -lx but specifies that the all symbols in library x should
             be available to clients linking to the library being created.  This was previously
             done with a separate -sub_library option.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文