duplicate symbol - ios

I have two framework(A.framework and B.framework).
B.framework link with A.framework, and I have a project,the project link With A and B,then link error :duplicate symbol
how to solve the problem? thanks

The two frameworks probably define a class or function with the same name. If the libraries are yours, you should rename your symbols using prefixes as described here. If not, see this answer — you probably won't be able to work around this without changing the libraries.

Related

Linker Error in iOS (duplicate symbols for architecture x86_64) when running on Xcode simulator

duplicate symbol _llvm.cmdline in:
/Users/inntot/Documents/navigationdrawer 2 2 2 2 2/Pods/GoogleInterchangeUtilities/Frameworks/GoogleInterchangeUtilities.framework/GoogleInterchangeUtilities(Descriptor.pb.o)
/Users/inntot/Documents/navigationdrawer 2 2 2 2 2/Pods/GoogleSymbolUtilities/Frameworks/GoogleSymbolUtilities.framework/GoogleSymbolUtilities(overload.o)
duplicate symbol _llvm.embedded.module in:
/Users/inntot/Documents/navigationdrawer 2 2 2 2 2/Pods/GoogleInterchangeUtilities/Frameworks/GoogleInterchangeUtilities.framework/GoogleInterchangeUtilities(Descriptor.pb.o)
/Users/inntot/Documents/navigationdrawer 2 2 2 2 2/Pods/GoogleSymbolUtilities/Frameworks/GoogleSymbolUtilities.framework/GoogleSymbolUtilities(overload.o)
A duplicate symbol error means that somewhere in your project being compiled, something that can only be defined once (like a function, const or class) is being defined twice, and hence the name, duplicated, so the compiler is unsure which definition to use.
However, it is highly likely that this is not a problem with you. These particular symbols, namely _llvm.cmdline and _llvm.embedded.moduleare not generally user-defined symbols and are generally created instead by a framework that you are using, people have encountered this error using frameworks by Twitter and Facebook as well. Looking at the paths to the two files where there are conflicting symbols confirms my suspicion. The errors are being generated in a file in the Google Utils framework.
Firstly, if you made any changes to these google framework files themselves, undo them, as your added or changed code may be the problem.
There are a few fixes that may work for you. The first is that this could be a cocoapods issue. Ensure that you have the default "Debug" and "Release" build configurations in your project, otherwise cocoapods will not handle this well. The next fix that I would suggest is to not include the GoogleInterchangeUtilities framework in the project. GoogleSymbolUtilities was in fact introduced to fix this error cropping up in other google frameworks, so try ONLY including googleSymbolUtilities in your project rather than both symbolutilities and interchangeutilities. Failing that, If there are other versions of these two google frameworks you can download, download a different version, as a fix might have been released or you can find a version before this bug occurred.
If none of these work for you then I would advise getting in touch with google to notify them of this issue, and then sitting tight for a fix.
You can try
Project-> Build Settings-> Enabled bit code (change it From Yes to No) i hope it works for you, if it doesn't please check your pods updated or not or if still your facing problem give some details about issue.

How to find unused properties for iOS class?

I cannot find any similar questions on this topic, which seems strange..
I have what is turning out to be a rather large project. As I build each chunk, I'm aware that I must be making properties and other resources, that do not end up being used.
Is there a way to find these?
Good question. I always need this too in my projects. What I do is either use search for .property or setProperty etc. in the whole project.
Or I traverse the .h files and comment out the property declarations that I suspect I might not be using and hit Command+b and see if it gives any errors.
I hope there is a function/tool specifically built for this need.

Rewriting symbols in static iOS libraries

I am working on an iOS app which links several static libraries. The challenge is, those linked libraries define same method names with different implementations. Oddly, I don't get any duplicate symbol definition errors; but, to no surprise, I end up with access to only one implementation of the method.
To be more clear, say I have libA and libB and they both define a global C method called func1()
When I link both libA and libB, and make a call to func1(), it resolves to either libA's or libB's implementation without any compilation warning. I, however, need to be able to access both libA's func1() and libB's func1() separately.
There's a similar SO post that explains how it can be done in C (via symbol renaming) but unfortunately, as I found out, objcopy tool doesn't work for ARM architecture (hence iPhone).
(I will submit it to the App Store, hence, dynamic linking is not an option)
It appears that you are in luck - you can still rename symbols with the ARM binary format, it's just a bit more hacky than the objcopy method...
NOTE: This has only been tested minimally, and I would strongly advise you to make a backup of all libraries in question before trying this!
Also note that this only works for files not compiled with the C++ compiler! This will fail if the C++ compiler was used on these files.
First, you will need a decent hex editor, for this example, I will be using Hex Fiend.
Next, you will open up a copy of your of of your libraries, let's call it lib1-renamed.a, and do the following with it:
Find the name of the symbol you wish to re-name. It can be found using the nm tool, or, if you know the header name, you should be set.
Next, you will use hex fiend, and to a textual replace of the old name (in this case foo), and give it a new name (in this case, bar). These names must have the same length, or it will corrupt the binary's offsets!
Note: if there is more than one function that contain's foo's name in it, you may have problems.
Now, you must edit the headers of the library you changed, to use the new function name (bar) instead of the old one.
If you have done the three simple† steps above properly, you should now be able to compile & link the two files successfully, and call both implementations.
If you are trying to do this with a universal binary (e.g. one the works on the simulator as well), you'd be best off using lipo to separate the two binaries, using objcopy on the i386/x64 binary, and then using my method on the ARM binary, and lipo it back together.
†: Simplicity is not guaranteed, nor is it covered by the Richard J. Ross III super warranty. For more information about the super warranty, call 1-800-FREE-WARRANTY now. That's 1-800-FREE-WARRANTY now!

Preventing "duplicate symbol" errors with iOS frameworks

Apple uses the following code in the header of all its framework classes.
#if !defined(__COREFOUNDATION_CFARRAY__)
#define __COREFOUNDATION_CFARRAY__ 1
...
#endif
Is this a recommended approach for eliminating "duplicate symbol" linker errors, when designing classes or categories for framework use, or are these left over protection from the use of #include instead of #import in c?
Research into this has lead me to this article on include guard
NOTE: this question is not asking how to fix a duplicate symbol error, but instead asking if there is any way of preventing your own code from causing the problem if its included more than once in a project.
You're right about the include guard - there's probably some compatibility reason it's not been removed from the source.
However, this won't really protect you against duplicate symbols much.
For example,
What if you have two third party library, each of which uses the SBJSON library (I had this happen to a colleague a few weeks ago).
Each of the libraries was compiled seperately so, from their point of view, SBJSON was only included once. However, when I came to link my app I couldn't because I had duplicate symbols.
I had to solve this by manually removing the symbols from one of the .a library files (This link shows it's quite a common problem!)
EDIT : This link is a much clearer step by step solution to the problem
Apple uses the following code in the header of all its framework classes.
Not necessarily for the ObjC APIs. But CoreFoundation, yes they use include guards. It's still idiomatic in many camps to use traditional #includes in C sources, and to use #import for objc sources (#import is a compiler extension, not traditional C).
Is this a recommended approach for eliminating "duplicate symbol" linker errors
No, it does not prevent linker errors; it can result in duplicate declaration errors during compile phases.
If you're getting duplicate symbol linker errors, the problem is something else, such as visibility of definition. For that, you should provide an example of your troubling program.

How do I get XCode4 to find libgcov.a

I've been building a static library to share between multiple iOS projects, and I want to use gcov (or any code coverage analysis tool) to tell me where I'm missing my tests. However, when I enable gcov by following these directions: http://supermegaultragroovy.com/blog/2005/11/03/unit-testing-and-code-coverage-with-xcode/
I get this error from Libtool:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: can't locate file for: -lgcov
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: file: -lgcov is not an object file (not allowed in a library)
For some reason XCode4 can't find the libgcov.a file. It is in many places on my system but for some reason it can't be found. I'm fairly new to XCode, and gcc based programming in general, so I'm not sure how I can fix this, my guess is that I just have to tell it specifically where to find libgcov.a but I'm not sure how to go about that.
Looks like I found a solution. Crazy XCode seems to treat static libraries completely different when invoking gcc. And I thought MSBuild was a build system from hell... it's a snap and at least there are books about it.
Anyway, here's how you do it:
Add $(PLATFORM_DEVELOPER_USR_DIR)/lib to your "Library Search Paths" build setting for your static library and tick the "Recursive" check box.
Works for me, let me know if it works for you.
This may help in solving your issue, have a look in to it
GTM

Resources