`*.framework`、`*.dylib` 和 `*.a` 库有什么区别

What's the difference between `*.framework`, `*.dylib` and `*.a` libs

我有一个项目,在框架中,有*.framework*.dylib*.a库。

我想知道它们是什么?以及它们之间的区别。

动态库和静态库

首先,库是资源和代码本身的集合,为一种或多种体系结构编译。

静态库(*.a):

In the case of static libraries (*.a), the code that the app uses is copied to the generated executable file by a static linker during compilation time.

动态库(*.dylib):

Dynamic libraries (*.dylib) are different from static libraries in the sense that they are linked with the app’s executable at runtime, but not copied into it. As a result, the executable is smaller and, because the code is loaded only when it is needed, the startup time is typically faster.

动态和静态框架:

For frameworks, we first need to understand the bundle concept (as a framework is a specific kind of a bundle). A bundle is a file directory with subdirectories inside. On iOS, bundles serve to conveniently ship related files together in one package – for instance, images, nibs, or compiled code. The system treats it as one file and you can access bundle resources without knowing its internal structure.

The library may also have additional resources: headers, localization files, images, documentation, and examples of usage. We can bundle all of this together in one bundle – and the name of this is the framework.

Static frameworks contain a static library packaged with its resources. Dynamic frameworks contain the dynamic library with its resources. In addition to that, dynamic frameworks may conveniently include different versions of the same dynamic library in the same framework!

其他有用的参考资料:

Hackernoon

Runtastic

Static library

Software framework

更新:

感谢您接受我的回答!

为一种或多种架构编译?

Every architecture requires a different binary, and when you build an app Xcode will build the correct architecture for whatever you’re currently working with. For instance, if you’ve asked it to run in the simulator, then it’ll only build the i386 version (or x86_64 for 64-bit).

This means that builds are as fast as they can be. When you archive an app or build in release mode, then Xcode will build for all three ARM architectures, thus allowing the app to run on most devices. What about the other builds though?

Naturally, when you build your framework, you’ll want developers to be able to use it for all possible architectures, right? Of course you do since that’ll mean you can earn the respect and admiration of your peers.

Therefore you need to make Xcode build for all five architectures. This process creates a so-called fat binary, which contains a slice for each of the architectures.

arm7: Used in the oldest iOS 7-supporting devices
arm7s: As used in iPhone 5 and 5C
arm64: For the 64-bit ARM processor in iPhone 5S
i386: For the 32-bit simulator
x86_64: Used in 64-bit simulator

Raywenderlich: Multi-Architecture