title: Problem of duplicate-symbol caused by lib(a)
date: 2016-01-07 12:23
tags: Technology#
Problem of duplicate-symbol caused by lib(a)#
Links:
- Solution to conflicts in iOS lib(.a) libraries
- Solution to conflicts in two static libraries with the same file name in iOS
Explanation#
First, you need to determine if it is this type of error.
Then, you can follow the modification steps in the first link, or you can refer to the following steps.
When importing third-party lib(.a) libraries, conflicts may occur due to the fact that the third-party lib library also imports open source code that is the same as the existing project.
Check the supported framework types of the lib library one by one.#
i386: Simulator;
armv7: iPhone 4;
armv7s: iPhone 5, iPhone 5s;
arm64: iPhone 6, iPhone 6 Plus.
-
First, copy the conflicting .a file to a separate folder, and then use the command line to enter that folder.
-
Check the supported framework types of the lib library. Note that lib.a or libRyFitLibrary.a below are the .a files that caused the error.
admin-imac:testlib admin$ lipo -info lib.a 2 Architectures in the fat file: lib.a are: armv7
armv7s arm64 3 admin-imac:testlib admin$
fat file: indicates that the lib library file merges multiple framework lib libraries. Here, it merges armv7 and arm64. If the lib library of the simulator is also merged, there will be an i386 identifier here.
Separate the .a library of armv7 type#
admin-imac:testlib admin$ lipo -extract_family armv7 -output lib_armv7.a lib.a
admin-imac:testlib admin$ lipo -info lib_armv7.a 3 Architectures in the fat file: lib_armv7.a are: armv7 armv7s
If the separated lib_armv7.a is still a fat file, further separation is needed. Only Non-fat files can be separated into .o files. So, continue with the following steps.
Separate the .a library of arm64 type#
arm64 is the newest framework in the iOS system. It was found through multiple experiments that it is impossible to separate the arm64 version Non-fat file by following the steps of separating armv7 and armv7s. However, it was discovered that it can be directly separated using the following command.
admin-imac:testlib admin$ lipo lib.a -thin arm64 -output lib_final_arm64.a
admin-imac:testlib admin$ lipo -info lib_final_arm64.a
input file lib_final_arm64.a is not a fat file
Non-fat file: lib_final_arm64.a is architecture: arm64
Separate the target .o files#
Through the above separation, the lib libraries of the armv7 and arm64 frameworks can be separated. Next, create a folder for each framework to save the separated .o files from the .a library. The same steps apply to other frameworks. Here is an example using armv7:
admin-imac:testlib admin$ mkdir armv72
admin-imac:testlib admin$ cd armv73
admin-imac:armv7 admin$ ar -x ../lib_final_armv7.a
At this point, let's take a look at my initial error again.
It can be seen that the problem is with Reachability.o. By using the ls command above, it can be seen that both folders indeed contain this .o file.
Delete the conflicting .o files from the separated .o files. All folders need to be deleted. Only one is demonstrated below.#
Merge the remaining .o files into lib(.o), pay attention to the folder location#
admin-imac:arm64 admin$ libtool -static -o ../libarm64.a *.o
It can be seen that two new files, libarm64.a and libarmv7.a, are generated after deleting the conflicting files.
Merge the final universal static library#
admin-imac:testlib admin$ lipo -create -output libs.a libarmv7.a libarmv7s.a libarm64.a
admin-imac:testlib admin$ lipo -info libs.a
Architectures in the fat file: libs.a are: armv7 armv7s arm64