Issue of duplicate-symbol caused by lib(a)#
Links:
- Solution to conflicts in iOS lib(.a) libraries
- Solution to conflicts caused by 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 start by following the first link for modifications, or you can refer to the following steps.
When importing third-party lib(.a) libraries, conflicts may often occur due to the third-party lib library importing the same open source code as your existing project, resulting in .o conflicts.
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 I made mistakes with.
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, and here it merges armv7 and arm64. If the lib library of the simulator is also merged at the same time, there will be an i386 identifier here.
Separate the .a library of the 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 you find that the separated lib_armv7.a is still a fat file, further separation is required. Only Non-fat files can be separated into .o files. So still
Separate the .a library of the arm64 type#
arm64 is the newest framework in the iOS system. No matter how you separate armv7 and armv7s, you cannot separate the Non-fat file of the arm64 version. After multiple attempts, it was found 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 one by one. Next, create a folder for each framework to save the separated .o files. The same applies to others. 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
Now let's take a look at my initial mistake again,
It can be seen that the problem is with Reachability.o. By using the ls command above, you can see that there is indeed this .o file in both folders.
Delete the conflicting .o files from the separated .o files, all folders need to be deleted, and only one is demonstrated below#
Merge the remaining .o files into lib(.o), pay attention to the folder they are in#
admin-imac:arm64 admin$ libtool -static -o ../libarm64.a *.o
You can see 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