Duplicate Symbol XCode duplicate library for same library? - iphone

Do you have any idea?
Why XCode compilation give this result?
ld: duplicate symbol _kJSONDeserializerErrorDomain in
/Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o)
and /Users/Shared/_BUILDS_/Debug-iphoneos/libLACDLibrary.a(CJSONDeserializer.o)

I have exactly the same problem. And it only complains for arm6 build (not arm7 build). I found a workaround: remove "-all_load" in Other linker flag under Build<-Get Info<-Target. I am not sure whether it is a correct workaround. I hope somebody can explain further and provide the correct workaround if this one is not.

This error occurs if you link the same library into your project multiple times.
Project dependencies are subtly different from linking the libraries together. It is okay to have several projects depend on the same shared library project X; however, make sure that only one of the projects actually links the library.

Hey, you probably have a duplicate reference in XCode to CJSONDeserializer, so it's compiled and linked twice.

I hit this issue with code like the following in a file called Common.h:
void dumpViews(UIView* view, NSString *text, NSString *indent) {
// ...
}
By adding static in front of the method definition it cleared the problem up for me:
static void dumpViews(UIView* view, NSString *text, NSString *indent) {
// ...
}

Related

ARC Semantic Issue: No visible #interface for Class declares the selector

Pretty basic stuff but i am unable to troubleshoot where the problem is. In my project, i have a class named "TheFeedStore" with following two methods:
- (BOOL)hasItemBeenRead:(RSSItem *)item
{
............
}
- (void)markItemAsRead:(RSSItem *)item
{
.........
}
I am using the following class method so other classes can access these methods using it:
+ (TheFeedStore *) sharedStore
{
static TheFeedStore *feedStore = nil;
if (!feedStore) {
feedStore = [[TheFeedStore alloc] init];
}
return feedStore;
}
In one of my another class, i can easily access the above methods by writing
if ([[TheFeedStore sharedStore] hasItemBeenRead:item])
or
[[TheFeedStore sharedStore] markItemAsRead:entry];
But in another class if i try to access these methods in a similar manner, i get the error "No visible #interface for 'TheFeedStore' declares the selector 'hasItemBeenRead:"
1) I have imported TheFeedStore.h file in the classes from i am
accessing these methods of TheFeedStore class.
2) I have checked like 10 times and there is no typo.
3) The methods i am accessing are also declared in the header file of
TheFeedStore.h
UPDATE: Just to check, i have declared another test method in TheFeedStore.h, same result, one class can access the newly created method while rest of the three classes cannot.
UPDATE: I have tried creating more methods in the TheFeedStore.h just for troubleshooting this issue. The new methods are also not accessible from the other classes. But if the return type of these new methods is (RSSChannel*) which is another model class in my project, than they become accessible. If their return type is other than some class like (void) and (BOOL) then they are not accessible. Here is my TheFeedStore.h https://gist.github.com/jessicamoore112/5558473
You have said that you are using #class instead of #import in your header files, the methods that you are trying to access are declared in the header files and there are no typos of any kind.
In such cases, usually no body points this issue but i am going to do it anyway because i have faced such issues many times. You have probably created many copies of your project to work on each functionality and also keeping a working project.
When you do this, sometimes Xcode is still using the older copies of few files. That means it is still using the older copy of the TheFeedStore.h when the methods you are trying to access were not declared by you.
How to solve this problem is very simple. Go to the file from which you are trying to access the methods and the files in which these methods are declared.
In the Utilities section on the right hand side, check the location and full path under "Identity and Type" area.
First check the names of the project, if it is different from the project name that you are working on, that means Xcode is still pulling the old copies of the files from the previous revision of your project. See the blue arrows where the project name is 13SampleMoreRequests in my case.
If this name is same as your project name, then my answer does not solve your problem. If its different, you should use the new copies of the file by browsing the new location using the sign that is pointed out by red arrow.
Once you browse and use the new files, your problem will be solved and you will be able to access the methods. If you still can't, copy these files, delete from the project and then add them again and you won't face this problem.
Hope this helps!
Cyclical imports, e.g. A.h imports B.h while also B.h imports A.h is the most common problem.
In C, cyclical imports won't work and one of the imports will be silently ignored. Make sure you are not having a cyclical import. If you do, solve it (e.g. using forward declarations).
Import problems can be also easily inspected if you generate the preprocessed output (you can find it in one of the Xcode menus).
That might sound silly, but I have similar cases once in a while and sometimes just simple quitting and starting xcode helps, it tends to stuck sometimes.
Also, sometimes cleaning the project helps.
'Cause I have very similar to yours singleton code and it works fine.
Guys I had encountered the exact same issues. After some searching on SO and the search engine I was able to solve it.
In my Case I have four files:
RadioStation.h
RadioStation.m
ViewController.h
ViewController.m
My mistake was to place all my methods in RadioStation.m and only put my variables on radioStation.h
So when I import radioSation.h on my ViewController.m and try to define methods for button-click on my app that's where the problems started.
I got the error/warnings "ARC Semantic Issue: No visible #interface for Class declares the selector" every time I built or ran the app simulator.
My Solution was to go back to RadioStation.h file and just declare all my methods there.
Since they were already defined on RadioStation.m I was good to go.
So make sure you have properly declared your methods on the file that is going to be imported on your viewControllers.
Hope that helps.
In my case I had some very strange path entries in
Framework Search Paths
Library Search Path
(Targets -> YOUR_APP_NAME -> Build Settings in "Search Paths" section)
I removed them and the error messages are gone.

Xcode Static Library Template... build doesn't contain headers?

So I'm using the Static Library template included in Xcode. Right now just trying to build a simple template to see how static libraries really work.
Anyways in my static library I have two classes:
mylibrary (.h/.m) - This is simply an NSObject
modalView (.h/.m) - This is a UIViewController
The problem though is when I build the static library. The project builds the mylibrary.a file... however there is no "Headers" folder in the output. This means that when I add the library to my other project it gives "undefined" errors because it can't find the .h file for myLibrary.
Any ideas on how to fix this?
Thanks
You need to drag .h files to the new project, along with .a file
I have a bunch of scripts here:
https://github.com/drekka/dUsefulStuff/tree/master/scripts
Which I use to build static libraries and frameworks. You might find them useful in helping to assemble your library. The main (controller) build script is here
https://github.com/drekka/dUsefulStuff/blob/master/build.sh

Core-Plot: Unknown class CPLayerHostingView in Interface Builder file

Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.

objective-c static library class category, override method not working

I am using Three20 for the iphone and I am trying to change what a method does within it by using a class category. It compiles fine, but I never reach the break point in it.
I'm assuming a class category affects all instances of the class, so I don't have to recompile the static library for it to work.
I also know that the class I'm using for the category is being seen because if I add a 'x' to the end of the class name when I interface and implement the category the compiler fails.
Any guidance here is VERY appreciated.
As is pointed out here, you'll need the -all_load option to be set in your application's Other Linker Flags in order to have categories be linked against static libraries in iPhone OS 3.0. -ObjC should do the trick as well, but it's not working on the current SDK. As of the LLVM compiler in Xcode 4.2, they fixed the linker bug that prevented the Other Linker Flag of -ObjC from working correctly, so you no longer need to use -all_load (which has some nasty side effects). -ObjC should be all you need to get categories to be pulled in from your static library.
This might be contributing to your problem, although I think Three20 requires those linker flags to be set for it to link properly with your application in the first place, so you might already have these flags in place.
When two categories override the same method on the same class in the same binary, it isn't defined which override will take precedence. For best results, create a subclass and then override the method on that. Alternatively, since Three20 is Apache-licensed, you can make your change in the library itself.
I have a project that is linking to a static library and yes the -all_load flag is required when installing on the device with the 3.0 sdk. -ObjC was all that was needed for the simulator.

Calling method on category included from iPhone static library causes NSInvalidArgumentException

I have created a static library to house some of my code like categories.
I have a category for UIViews in "UIView-Extensions.h" named Extensions.
In this category I have a method called:
- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;
Calling this method works fine on the simulator on Debug configuration.
However, if try to run the app on the device I get a NSInvalidArgumentException:
[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
It seems for some reason UIView-Extensions.h is not being included in the device builds.
What I have checked/tried
I did try to include another category for NSString, and had the same issue.
Other files, like whole classes and functions work fine. It is an issue that only happens with categories.
I did a clean all targets, which did not fix the problem.
I checked the static library project, the categories are included in the target's "copy headers" and "compile sources" groups.
The static library is included in the main projects "link binary with library" group.
Another project I have added the static library to works just fine.
I deleted and re-added the static library with no luck
-ObjC linker flag is set
Any ideas?
nm output
libFJSCodeDebug.a(UIView-Extensions.o):
000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:]
00000000 t -[UIView(Extensions) fadeInWithDelay:duration:]
000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:]
00000abc t -[UIView(Extensions) firstResponder]
000006b0 t -[UIView(Extensions) hasSubviewOfClass:]
00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:]
000005cc t -[UIView(Extensions) rotate:]
000002d8 t -[UIView(Extensions) shrinkToSize:withDelay:duration:]
000001b8 t -[UIView(Extensions) translateToFrame:delay:duration:]
U _CGAffineTransformRotate
000004a8 t _CGPointMake
U _CGRectContainsPoint
U _NSLog
U _OBJC_CLASS_$_UIColor
U _OBJC_CLASS_$_UIView
U ___CFConstantStringClassReference
U ___addsf3vfp
U ___divdf3vfp
U ___divsf3vfp
U ___extendsfdf2vfp
U ___muldf3vfp
U ___truncdfsf2vfp
U _objc_enumerationMutation
U _objc_msgSend
U _objc_msgSend_stret
U dyld_stub_binding_helper
The only solution that worked was to include:
"-all_load"
in other linker flags.
EDIT: Be sure to add this flag to the project including the static library, not to the static library itself.
I know this isn't the correct method, but it is working for now.
It maybe a OS 3.0 issue since this was the work around for Three20 as well.
Unfortunately, due to the what categories work and the dynamic nature of the Objective-C runtime, not everything works well with static libraries. The reason you get this error is that the category implementation in the static library is never actually linked into the executable image because the compiler has no way of knowing that the implementation code will be needed at run-time.
In order to cure this, you can force the linker to copy object files from a static archive for any and all Objective-C Class and Category images. The downside is that your executable will include image code for classes that you may not be using at all. To get the linker to include the category code, add -ObjC to the OTHER_LD_FLAGS build setting in Xcode. Your category implementation will now be copied from the static archive to your executable and you won't get the runtime exception.
I just spoke to an Apple engineer about this, and this has been addressed in ld with versions >100. This is included in Xcode 4. He walked me through this and I tried it myself and indeed the category problem is fixed.
Take out "-all_load" and go back to "-ObjC" in your Build Settings with the new linker.
If you are on Xcode 3.2 you can avoid using -all_load and instead use -force_load for just the library in question, which should be slightly more efficient.
This is described in a recently updated Apple Technical QA: http://developer.apple.com/mac/library/qa/qa2006/qa1490.html
The issue that -all_load or -force_load linker flags were needed to link categories has been fixed in LLVM. The fix ships as part of LLVM 2.9 The first Xcode version to contain the fix is Xcode 4.2 shipping with LLVM 3.0. The mentioned fixes are no longer needed when working with Xcode 4.2. The -ObjC flag is still needed when linking ObjC binaries
I ran into this problem recently. I was unable to get the -all_load to work, when I noticed that another category I had DID work. I was lazy for this category and included it in with another file.
I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. After doing this my categories started working even after I removed the -all_load flag.
This was on iPhone OS 3.1.3.
This certainly is not the RIGHT way to fix it, but it seemed to work.
Full sample code is on my blog for my (trivial) categories.
I just had this same problem but adding any combination of the described flags (-ObjC, -all_load, -force_load) did not work.
It turned out that I had not checked the box "Add to Target" when adding the files to the project. I removed the files from the project and added them again, this time making sure that that box was checked. This fixed the problem.
In the past I was able to force linkage of the category with -u .objc_category_name_UIView_Extensions, but with the 3.0 dev environment that's broken and the only option seems to be -all_load.
I had the same problem with Categories in my static library. In my case, "-all_load" didn't help as it caused loads of build errors (my static library is a wrapper around another private C/C++ lib).
I solved it by a hack suggested at http://iphonedevelopmentexperiences.blogspot.com/2010/03/categories-in-static-library.html which simply involved adding a dummy (empty) class definition to the category files. Using this hack, I kept "-ObjC" but dropped "-all_load" in the application linker settings and it worked fine on the device.