dylib文件的含义是什么?

发布于 2024-12-16 23:59:00 字数 156 浏览 0 评论 0原文

我的 C++ 编译器创建包含动态库的“dylib”文件。 .dylib 和 .so 文件有什么区别?

Mach-O 格式的文件和 ELF 格式的文件有什么区别?我必须构建文件以供以后在 iOS(仅限静态库/Mach-O)和 Android(ELF)下使用。

谢谢!

My C++ compiler creates "dylib" files which contain dynamic libraries. Whats the difference between .dylib and .so files?

And what is the difference between files in Mach-O format and files in an ELF format? I have to build files for later use under iOS (static libraries only/Mach-O) and Android (ELF).

Thanx!

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

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

发布评论

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

评论(1

听,心雨的声音 2024-12-23 23:59:00

我发现:

Mach-O 的一项让很多人感到惊讶的功能是严格的
共享库和动态可加载模块之间的区别。
在 ELF 系统上两者是相同的;可以使用任何共享代码
作为库并用于动态加载。使用otool -hv some_file查看
some_file 的文件类型。

Mach-O 共享库的文件类型为 MH_DYLIB,并带有
扩展名.dylib。它们可以与通常的静态链接
链接器标志,例如 -lfoo 表示 libfoo.dylib。然而,他们不能
作为模块加载。 (旁注:可以加载共享库
通过 API 动态地进行。然而,该 API 与
捆绑包的 API 和语义使其对于 dlopen() 毫无用处
仿真。最值得注意的是,共享库无法卸载。)[这
不再正确 - 您可以将 dlopen() 与 dylib 和包一起使用。
但是,dylib 仍然无法卸载。]

可加载模块在 Mach-O 语言中称为“包”。他们有
文件类型 MH_BUNDLE。由于没有涉及的组件关心它,所以它们
可以携带任何扩展。扩展名 .bundle 被推荐
Apple,但大多数移植软件都使用 .so
兼容性。捆绑包可以通过 dyld 动态加载和卸载
API,并且有一个在其之上模拟 dlopen() 的包装器
API。 [dlopen 现在是首选 API。] 无法链接
反对捆绑包,就好像它们是共享库一样。然而,它是
捆绑包可能链接到真正的共享库;那些
加载包时将自动加载。

要在 OS X 上编译普通共享库,您应该使用 -dynamiclib
和扩展名 .dylib。 -fPIC 是默认值。

I found that:

One Mach-O feature that hits many people by surprise is the strict
distinction between shared libraries and dynamically loadable modules.
On ELF systems both are the same; any piece of shared code can be used
as a library and for dynamic loading. Use otool -hv some_file to see
the filetype of some_file.

Mach-O shared libraries have the file type MH_DYLIB and carry the
extension .dylib. They can be linked against with the usual static
linker flags, e.g. -lfoo for libfoo.dylib. However, they can not be
loaded as a module. (Side note: Shared libraries can be loaded
dynamically through an API. However, that API is different from the
API for bundles and the semantics make it useless for an dlopen()
emulation. Most notably, shared libraries can not be unloaded.) [This
is no longer true—you can use dlopen() with both dylibs and bundles.
However, dylibs still can't be unloaded.]

Loadable modules are called "bundles" in Mach-O speak. They have the
file type MH_BUNDLE. Since no component involved cares about it, they
can carry any extension. The extension .bundle is recommended by
Apple, but most ported software uses .so for the sake of
compatibility. Bundles can be dynamically loaded and unloaded via dyld
APIs, and there is a wrapper that emulates dlopen() on top of that
API. [dlopen is now the preferred API.] It is not possible to link
against bundles as if they were shared libraries. However, it is
possible that a bundle is linked against real shared libraries; those
will be loaded automatically when the bundle is loaded.

To compile a normal shared library on OS X, you should use -dynamiclib
and the extension .dylib. -fPIC is the default.

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