iOS Build settings Other Linker Flags - ios

I have a project which is written in swift and i was trying to integrate GoogleSignIn in my project when the program kept crashing saying:
-[__NSDictionaryI gtm_httpArgumentsString]: unrecognized selector sent to instance
Then I googled the problem and found a solution to add -ObjC Other Linker Flag to my build settings.
So my question is what does this step does and how did it fix the problem.
Can anyone please explain what is Other Linker Flag and what it does?

For your explanations about the "Other Linker Flag" and why fix the problem like this see :
https://developer.apple.com/library/mac/qa/qa1490/_index.html
This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

Related

Reason to include "-ObjC" in Xcode

We include "-ObjC"in other linker flags of project settings in Xcode if we include any external libraries or frameworks can any one tell me what is the reason for it and what it does if we include it.
Thanks in Advance..
It's explained pretty well in Apple's QA1490.
Key excerpts:
Objective-C does not define linker symbols for each function (or
method, in Objective-C) - instead, linker symbols are only generated
for each class.
...
To resolve this issue, the target linking against the static library
must pass the -ObjC option to the linker. This flag causes the linker
to load every object file in the library that defines an Objective-C
class or category
Categories are most known use case for this flag (as Apple's QA1490 explains), but they are not the only reason why this flag is needed.
Since Objective-C is a dynamic language which makes things like NSClassFromString() possible, the standard behaviour of C linker of including only actually used symbols (and throwing away all others) does not work, because there is no way to find out whether some symbols are actually used in some indirect ways like concatenating strings then calling NSSelectorFromString or NSClassFromString.
Consider xib/nib files for example: they don't participate in linking stage, yet they may instantiate library classes which are not referred by anything but this nib file. If linker threw away those classes as unused, the nib couldn't load and work properly.
The only way to ensure nothing is lost is to include every Obj-C class from a library at link time, and this flag does that.
-ObjC linker flag causes the linker to load ever object file in the library that defines an Objective-C class or category.
Why to use -ObjC linker flag - Apple Documentation?

Problems in adding core plot frame work with existing project in Workspace

I want to use core plot in my project to display bar&scatter plots.Before that I made a prototype project where I was successful in plotting those two. But when I tried to include it into my project faced some problems.
1) My project has a static library so according to the https://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications, I added coreplot-cocoatouch.xcodeproj added too as a static library to my project and i set linker flags -ObjC as well for my app project then compiler throws a Mac linker error "Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1"
2) If I did not include -ObjC it throws error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance "
I am not able to find where am I doing wrong.Is it the problem with ARC because my project doesnt use ARC but as per some forums, I found we can use non ARC and ARC libraries in a single workspace.
I tried with CorePlot versions 1.3 and 1.4 & using Xcode 4.5, are these two arc or not.
Any help is appreciated.
Thanks in Advance.
1 Possible reason may be that there are 2 different versions (duplicate) of Core-Plot Exists in your build directory.. or you have #import .m class instead of .h in your code.. sometimes same thing happens if you have 2 different classes with same name exists in your code.. Also do try cleaning your build directory and check again.
Use the Core Plot dependent project or the pre-built static library, not both.
The -ObjC linker flag is required. You also need the -all_load linker flag. That error message means that one of the category methods added by Core Plot did not load at runtime; the -all_load flag tells the linker to make sure the app knows to load those methods, too.

Significance of -ObjC value in Other Linker Flags: GMaps SDK

I was trying out google maps sdk integration with iOS 6.1. I am successfully able to populate gmap on iOS simulator by using instructions given on
GMaps for iOS starting guide
Then what the issue with it:
It works great when I use it as a separate project. But when I club the above project code with my existing application, then it behaves weird, and all the errors generates due to inclusion of -ObjC value in Other Linker Flags in Build Settings.
Error
duplicate symbols for architecture i386
When I skip step 7 (GMaps iOS), it doesn't give errors. Due to exclusion of -ObjC value, it doesn't able to identify a specific GMaps library class and its method:
[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent
My iOS application background:
Using a third party library SUP (Sybase Unwired Platform). Connecting SAP to iOS application. I guess there is something ambiguous with SUP environment enablement (Build settings) when I am trying to add GMaps library.
Seeking for your advices.
Thanks!
There many posts on SO about the duplicate symbols for architecture i386 error. Usually it means that you defined the same symbol twice in the one namespace. The last time I got this error was because I accidentally included a .m file instead of .h header file.
Have you checked the Build Architecture?
Try setting Build Active Architecture Only to Yes.
I was facing the same issue Today! -ObjC linker flag - When trying to add it to "Other Linker Flags" I get an error
I solved my problem, Here is what I'd suggest. Take your original project (without Gmaps and with SUP) and add the -ObjC flag to it. Are you still getting an error? If so, take Gmaps out of the equation. If you are still getting an error check in the warnings about which files it is warning you about. My problem was that I had two files libGoogleAnalytics.a and libGoogleAnalytics_debug.a and for some reason they could not coexist with the -ObjC.
Long story short, you need to find what libraries Gmaps is using that you already have in your project and remove one of them.
Please try this…
step 1: Add '-ObjC' to other linker flags in 'Build Settings' of your 'target' only not to the 'project'

Duplicate Symbol linker error

I have an existing app in which I added the json-framework. Now it won't compile due to a duplicate symbol linker error.
The error seems to be due to the installed Millenial Media ad network SDK which also links to the json-framework. It seems the json-framework must be already embedded in MMs .a static library file. If I dont add the SDK then I cant import the json-framework for use in my own code, but when I do the compiler raises this exception.
ld: duplicate symbol _OBJC_IVAR_$_SBJsonParser.maxDepth in /users/laptop/Developer/sandbox/testapp_sources_add_owntracking/testapp/AdNetworkLibs/MillenialMedia/libMMSDK.a(SBJsonParser.o) and /Users/laptop/Library/Developer/Xcode/DerivedData/testapp-bjxtaanqoewrondmjnucarxebkka/Build/Intermediates/testapp.build/Debug-iphonesimulator/testapp.build/Objects-normal/i386/SBJsonParser.o for architecture i386
collect2: ld returned 1 exit status
You can add the json framework header files without adding the json class implementation files. If these classes are in another library, then they will be linked with that library.
In your project, you have SBJsonParsor added twice.
This might have happend as some of the library (source) you are using (added to project) already have SBJsonParsor added without your active knowledge about the same.
You need to check your project hierarchy and remove one of the reference.

SDWebImage : setImageWithURL fails when used to set image of a UITableViewCell

When call setImageWithURL, it fails with following,
[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x149a20 2011-12-14 18:11:38.060 [781:707]
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIImageView
setImageWithURL:placeholderImage:]: unrecognized selector sent to
instance 0x149a20'
I can confirm I have included SDWebImage project and required headers correctly as I can use the SDWebImageManager successfully.
Following is the code where I called the UIImageView category method setImageWithURL
NSURL* url = [NSURL URLWithString:#"www.abc.com/abc.png"];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:#"abc.png"]];
As per:
linking objective-c categories in a static library
Due to a linker bug in XCode, you need to set the 'Other Linker Flags' setting your build target. Setting the flag as follows should eliminate this error.
-force_load ${BUILT_PRODUCTS_DIR}/libSDWebImage.a
This will solve the problem: Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:
If anyone, like me, still has problems after seeing all the other answers here (e.g. force_load or load_all) even after following all the proper installation instructions, here is what I have learnt after doing some search online:
This problem only happens when you use iPhone 5S or the 64-bit simulator
This is a problem with libwebp
The solution to this problem:
Only do this if you don't need the 64-bit processor for your app (too new to iOS programming to know if this sentence is valid)
Go to build settings > Architecture
Under Architecture, select Standard architectures (armv7,armv7s)
Under Build Active Architecture Only, make sure it is Yes for both Debug and Release
My source: https://github.com/rs/SDWebImage/issues/494
I hope this helps those who, like me, found this while trying to solve your problem =)
I ended up inserting all the .h and .m files into my project and then it worked fine. I got the same error when I only included the .a and .h files.
In the SDWebImage docs, it says that you have to set "Other Linker Flags" to -ObjC. This did not work for me. Instead, I set it to -all_load. I also had to remove -ObjC. The explanation for what is going on can be found here:
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
It also explains why -ObjC fails: "Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the f-all_load or -force_load flags"
Using -all_load increases the size of the executable. You can use -force_load to mitigate this somewhat. For SDWebImage 2.7.3, I did this by setting the following in "Other Linker Flags" in the Build Settings: "-load_all $(SRCROOT)/SDWebImage.framework/SDWebImage". Linking to libSDWebImage[ARC].a which is what some sources advise, didn't work for me.
Incidentally, in Xcode 4.4, it seems you have to do a slow double-click in order to change build settings properly. Doing a normal double-click shows the completely screwed up and non-working pop-up.
Solved the same problem adding the libSDWebImage.a to Build Phases > Link Binary with Libraries.
If you read the document here https://github.com/rs/SDWebImage at the bottom there is a download link with the CORRECT files to download. Following that example it works perfectly.
The mistake I made, and seemingly others to, is I downloaded the github project and tried using that.
Everything started to work for me once I linked "ImageIO.framework" to my main project.
You can also set 'Other Linker Flags' to -all_load. This solves the problem where an external framework (such as the filepicker framework) requires linking against SDWebImage.
-force_load is not fix fundamental problem (when achiveing problem happens)
to fix this linking problem..
edit scheme for SDWebImage,
run scheme set for release
run (with device)
libSDWebImage.a will be generated in release-iphoneos directory.
set target->BuildPhase->link Binarywithlibrary .. add this lib.
Done..
Make sure your compiled files have UIIMageView+AFNetworking.m in case you're using AFNetworking framework.
You need to add the libSDWebImage.a in your linked binaries, also check for other linker flags, it should be -ObjC
Checkout your choice when you pull files of SDWebimages into Xcode, do mark the "create groups" in added folders, and do not mark the "create folder references".
Mark exactly as the picture:

Resources