When the project is linked to a static library, you can delete the class to solve the duplicate symbol error.
If you use a static library in the project and specify the compilation option as-all_load (to make the Objective-C class load correct), in the static library, your project contains the same class name or has the same class name as other static libraries. In the static link, you must have encountered a "duplicate symbol" error similar to this.
For example, a third-party library (libProprietary. a) uses KissXML to parse and generate XML, and a static library (libBitsAndBobs. a) is also used in your project. If you use two libraries, you will get the duplicate symbol error of KissXML.
A rough and quick way is to remove the same class name from one of the libraries. The following describes how to implement it: general steps:
1. Check whether the static library is fat.
2. split it into two static libraries of armv6 and i386.
3. Solve the target file (. o file) in the static library)
4. Delete unnecessary target files
5. Synthesize static libraries of armv6 or i386
6. resynthesize the fat library.
1. First, we need to check whether the static library is a "fat file"
Indicates whether multiple architectures are included. You will find that many static iOS libraries are fat files, so that they can run on both the real machine and simulator.
$ Lipo-info libProprietary.
Ubuntures in the fat file: libProprietary. a are: armv6 i386
As we said, this library is a fat file (armv6 and i386 architectures ).
2. The tool we use can separate the fat static library into a static library for each architecture.
To do so. We also need to use the lipo command
$ Lipo-thin armv6 libProprietary. a-output libProprietary-armv6.a
3. We can also use ar to check the files in the static library and list the target files.
$ Ar-t libProprietary-armv6.a
_. SYMDEF SORTED
FOOBar. o
DDXMLDocument. o
DDXMLElement. o
DDXMLElementAdditions. o
DDXMLNode. o
4. As we expected, libProprietary. a contains the FOOBar. o target file, which we also have in KissMXL. We need to remove the target file from the static library, delete it, and package it into static library files.
First, unpack:
$ Mkdir libProprietary-armv6
$ LibProprietary-armv6 cd
$ Ar-x ../libProprietary-armv6.a
Now we have a folder libProprietary-armv6 that contains the target file
$ Ls-1
DDXMLDocument. o
DDXMLElement. o
DDXMLElementAdditions. o
DDXMLNode. o
FOOBar. o
_. SYMDEF SORTED
5. Delete the duplicate. o files and then regroup the packages:
$ Rm DDXML *. o
$ Libtool-static *. o-output ../libProprietary-armv6.a
To confirm that the target file has been removed, you can list it again;
$ Ar-t ../libProprietary-armv6.a
_. SYMDEF SORTED
FOOBar. o
So far, we have completed splitting the armv6 architecture and need to perform the same process on the i386 architecture.
$ Lipo-thin i386 libProprietary. a-output libProprietary-i386.a
$ Mkdir libProprietary-i386 & cd libProprietary-i386
$ Ar-x ../libProprietary-i386.a
$ Rm DDXML *. o
$ Libtool-static *. o-output ../libProprietary-i386.a
6. Finally, we need to re-combine the static libraries of armv6 and i386 architectures into a fat static library.
Lipo-create libProprietary-armv6.a libProprietary-i386.a-output libProprietary-noKissXML.a
If everything is correct, you can replace libProprietary. a with a libProprietary-noKissXML.a and there will be no errors for duplicate symbol anymore.
Original address http://atnan.com/blog/2012/01/12/avoiding-duplicate-symbol-errors-during-linking-by-removing-classes-from-static-libraries