This is the 20th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.

Three elements that link a library:

  • The header file
  • Location of library files
  • Library file name

App -> dynamic library A -> dynamic library B

For App, dynamic library A is linked properly, but dynamic library B is not in the path of the @rpath saved by dynamic library A and the install_name of dynamic library B:

Dynamic library B path = dynamic library A rpath + dynamic library B install_nameCopy the code
  • Solution: Change the Rpath of dynamic library A or copy dynamic library B to A specified path.

Methods a

Modify theThe dynamic library AtherpathforThe dynamic library Btheinstall_namePrevious absolute paths:

Way 2

CocoapodstoAppIn the importThe dynamic library BDuring the import process,CocoapodsWill help usThe dynamic library BCopy toApptheFrameworks/Directory:

Methods three

Manually using scriptsCopyThat will beThe dynamic library BCopy toApptheFrameworks/Directory:

Reverse dependencies for dynamic libraries

The reverse dependency of dynamic libraries, which can be found dynamically at run time because of the space of symbolsAppThe symbols. So, as long as no sign undefined errors are reported during compilation. Can be achieved by-u < symbol >To specify a symbol is the dynamic lookup symbol.

You can also mark the App as an upward referenced dynamic library by specifying -upward-l or -upward_framework

.

App wants to use the method of dynamic library B

ifAppWant to useThe dynamic library BThe first way is to letAppDirect linkThe dynamic library B. The second way is through-reexport_frameworkor-reexport_lWill againThe dynamic library BthroughThe dynamic library AExport toApp.Note ⚠️ : becauseCocoapodsself-generatedxcconfigThe file contains-framework AFNetworkingParameter, if you want to reAFNetworkingSpecified as-reexport_framework, it needs to be placed in$(inherited)The front.

AppInside Settings:

App -> dynamic library A -> static library B

Because when dynamic library A is generated and static library B is linked, all the code in static library B will be linked into it. So compiling links is not an error.

If dynamic library A does not want to expose the exported symbols (global symbols) of static library B, you can hide the global symbols of static library with -hidden-l .

Note ⚠️ : Because the xcconfig file automatically generated by Cocoapods contains the -l”AFNetworking” parameter, to re-specify AFNetworking as -hidden-l, inherited follows $(Inherited).

AppInside Settings:

App -> static library A -> static library B

When static library A is generated, only the header file information of static library B or the name of static library B is saved (auto-link). After the App links to static library A, it will link all the code of static library A into it. But the location and name of static library B are not known.

Methods a

throughCocoapodswillStatic library BIntroduced to theAppIn:

Way 2

Manually configure the location and name of static library B:

App -> static library A -> dynamic library B

When static library A is generated, only the name of dynamic library B is saved (auto-link). After the App links to static library A, it will link all the code of static library A into it. But App (the dynamic library B he links to) does not know the location of dynamic library B and does not provide rPATH. @rpath saved with install_name of dynamic library B:

Dynamic library B path = App rpath + dynamic library B install_nameCopy the code

Methods a

Introduce dynamic library B into your App via Cocoapods:

Way 2

configurationrpathAnd through the script willThe dynamic library BIntroduced to theAppIn:

Weak reference dynamic library

Marked weak imports, allowing the library to be unlinked at run time. For example, when a dynamic library links to a library file, the image Not found message is displayed if the library file is not in the specified path. Specify the library as weak imports with -weak-l or -weak_framework

. If the library is not found at runtime, the address and content of the library are automatically set to 0.