dylib文件是什么意思? [英] What's the meaning of dylib files?

查看:805
本文介绍了dylib文件是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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).

感谢!

推荐答案

我发现:

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

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

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.]

可加载模块在Mach-O语言中称为捆绑".他们有 文件类型MH_BUNDLE.由于没有涉及的组件在乎它,因此他们 可以携带任何扩展名.建议使用扩展名.bundle 苹果,但为方便起见,大多数移植软件都使用.so 兼容性.捆绑包可以通过dyld动态加载和卸载 API,并且在其顶部有一个可模拟dlopen()的包装器 API. [dlopen现在是首选的API.]无法链接 针对捆绑软件,就好像它们是共享库一样.但是,这是 捆绑软件可能与实际的共享库链接在一起;那些 将在捆绑软件加载后自动加载.

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.

要在OS X上编译普通共享库,应使用-dynamiclib 以及扩展名.dylib. -fPIC是默认设置.

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

这篇关于dylib文件是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆