Static linking a dylib
ios, objective-c, static, xcode
Solution
Static library that you create is not a separate process rather it is part of the process which gets created for your application(using the static lib). Shared dynamic libraries are loaded/shared per process, hence it is important that whichever frameworks(iOS frameworks are also dynamic libraries) or dylibs your static library links to, your application must also link with them so that at runtime the shared libraries get loaded for your app's process.
Further reading,
- Static Library
- How shared libraries work
- Shared Libraries and dynamic loading
- Dynamic Loading
Hope that helps!
Problem
I have a project which builds a static library (.a). This static library requires the `libz.dylib` to be present in the application. Now what I am trying to do is.. Link the `libz.dylib` with the static library itself so that the developers who will use my static library won't have to link `libz.dylib` with their Application. Here is what I have tried till now, and the errors that I encountered: If I just link the `libz.dylib` in `Link Binary with Libraries` build phase of the Static Library Target, and then use the final static library with the application: Undefined symbols for architecture i386: "_deflate", referenced from: If I also include `-lz` in the `Other Linker Flags` of Static Library Target, it gives error at the time of building the static library itself: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lz /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lz is not an object file (not allowed in a library) I am thinking if it is even possible to link a dynamic library with the static library, and if it is, how?