elf - dylib 文件的含义是什么?

标签 elf mach-o dynamic-library

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

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

谢谢!

最佳答案

我找到:

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.

关于elf - dylib 文件的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8158783/

相关文章:

c - ELF 文件中的多个程序头

x86-64 - 是否可以用编译后的二进制文件中的虚拟对象替换特定函数的每个实例?

target - 使用 FASM 的 Mach-O 二进制文件

ios - Xcode Apple Mach-O 链接器错误 1

linux - Linux 上 libgcc_s.so.1 的次要版本

linker - 在调用 ELF 的默认入口点之前是否运行任何用户模式代码?

compilation - *COM* 在 objdump 符号表中代表什么?

linux - GNU/Debian Linux 和 LD

c++ - 链接两个供应商提供的库时双重删除静态变量

elf - readelf -S 的输出中 ES、Lk、Inf 和 A​​l 列标题的含义是什么?