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 A
therpath
forThe dynamic library B
theinstall_name
Previous absolute paths:
Way 2
Cocoapods
toApp
In the importThe dynamic library B
During the import process,Cocoapods
Will help usThe dynamic library B
Copy toApp
theFrameworks/
Directory:
Methods three
Manually using scriptsCopy
That will beThe dynamic library B
Copy toApp
theFrameworks/
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 symbolsApp
The 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
.
App wants to use the method of dynamic library B
ifApp
Want to useThe dynamic library B
The first way is to letApp
Direct linkThe dynamic library B
. The second way is through-reexport_framework
or-reexport_l
Will againThe dynamic library B
throughThe dynamic library A
Export toApp
.Note ⚠️ : becauseCocoapods
self-generatedxcconfig
The file contains-framework AFNetworking
Parameter, if you want to reAFNetworking
Specified as-reexport_framework
, it needs to be placed in$(inherited)
The front.
App
Inside 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).
App
Inside 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
throughCocoapods
willStatic library B
Introduced to theApp
In:
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
configurationrpath
And through the script willThe dynamic library B
Introduced to theApp
In:
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
. If the library is not found at runtime, the address and content of the library are automatically set to 0.