Dilib Static Link

I have a project that creates a static library (.a).

This static library requires libz.dylib to libz.dylib present in the application. Now I'm trying to do it. Link libz.dylib to the static library itself so that developers who use my static library do not have to link libz.dylib to their application.

Here are what I have tried so far and the errors I came across:

  • If I just bind the build phase of libz.dylib to the Link Binary with Libraries of the static library object, and then use the final static library with the application:

    Undefined symbols for i386 architecture:

    "_ deflate" referenced by:

  • If I also include -lz in the Other Linker Flags of the Static Library Target object, it gives an error while creating the static library itself:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: cannot find file for: -lz /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/ bin / libtool: file: -lz is not an object file (not allowed in the library)

I think it is possible to link a dynamic library to a static library, and if so, how?

+4
source share
1 answer

The static library that you create is not a separate process, but is part of the process that is created for your application (using the static lib). Shared dynamic libraries are loaded / shared for each process, so it’s important that any framework (the iOS framework is also a dynamic library) or dylibs that your static library is associated with, your application must also link to them so that shared libraries are loaded at runtime for your application process.

Further reading

Hope this helps!

+2
source

Source: https://habr.com/ru/post/1499329/


All Articles