duplicate symbol errors with third party library

We use different commercial third party libraries when making iPhone applications. One of them got an update a few weeks back, but when we tried to integrate it into our application xcode threw out the following errors (actual library name hidden);

duplicate symbol _FBLoginViewButtonPressedPNG_retina in:
duplicate symbol _FBLoginViewButtonPressedPNG_standard in:
duplicate symbol _OBJC_METACLASS_$_FBLoginViewButtonPressedPNG in:

At first glance, the problem appears obvious. We are (inadvertently) including Facebook’s libraries twice and the compiler (or rather the linker) is confused which reference to use. The difficulty is that we only included the Facebook library once. So where was this second reference coming from? Did we accidentally include it without realizing it? A very far-fetched theory, but it wouldn’t hurt to check, so we removed the one reference we knew we included and tried building the application again.

Not surprisingly, we got a lot of “missing ABC” errors this time.

A bit of thought led to the conclusion that our third-party library might be embedding the facebook libraries within itself. The theory made sense – the problem started happening after we tried to integrate an update to their library.

Deciding that the problem was isolated, we reached out to our third-party library vendor for assistance. Initially, we got responses from them that the issue was under investigation. Then a week passed. Two weeks. I even got engaged. And the problem still persisted.

Quite frankly, I was more than willing to throw away the so-called “update” to the library and just use the older version. That at least, worked with our code. Unfortunately, the customer we were working for insisted to use the newer version. The old version you see, was meant for iOS6. With all the visual differences between iOS6 and iOS7, the interface didn’t really mesh well.

So what was left to do? The issue was caused by the third-party vendor’s new update, but they wouldn’t give us a timely fix. What options were left open to us? Throw our hands up in despair?

I was literally, at the end of my rope. Stuck between a rock and a hard place, I asked myself – would it be possible to manually remove the references to facebook’s API from the third party vendor’s library? Reverse-engineering the binary would probably by a violation of the Terms Of Service we agreed on when obtaining the library, but I was really desperate here.

So I tried it.

First step was to find out what exactly I was working with. For this, I used the “lipo” tool to analyze the binary library our third party vendor provided.

$ lipo -info SSSSS
Architectures in the fat file: SSSSS are: armv7 armv7s i386

Hmm… the library comes with 3 different architectures bundled in? Better to check them out one-by-one.

$ lipo -thin armv7 SSSS -output SSSS-armv7

What the above command does, is to split the static library named “SSSS” into a separate file for the architecture “armv7” (works because SSSSS is a fat file).

Next we need to analyze the file to list out its included object files. The “ar” tool comes to our rescue here.

$ ar -t SSSSS-armv7

A little down the list I came across these tell-tale entries,


Looks like the Facebook API to me!

Having identified the source of all the “duplicate symbol” problems, the next step is to get rid of them. For this, I created a new empty directory and unpacked the object files from the archive into it.

$ mkdir SSSSS-armv7.folder
$ cd SSSSS-armv7.folder
$ ar -x ../SSSSS-armv7

All that’s left to is to delete the problematic object files from this folder and repack the archive, like so;

$ rm FB*.o
$ libtool -static *.o -o ../SSSSS-armv7

You can use the “ar” tool to reconfirm that the libraries have been removed.

At this point, only the armv7 architecture had been cleaned. The above process needed to be repeated for all the architectures present in the third-party vendor’s library.

The second-to-last step is to recombine all the thin files into a big fat file again (for xcode to use).

$ lipo -create SSSSS-armv7 SSSSS-armv7s SSSSS-i386 -output SSSSS-noFacebook

Final step was of course, to attempt using this “reduced” library with our application in xcode. Happily enough, it worked! As a developer I was so relieved that it all came together – after so much pain too. And obviously, our customer is happy as well. As for the third-party library vendor? Who knows whats going on with them? I’m still a little annoyed that they put me through all those weeks of pain.


Avoiding duplicate symbol errors during linking by removing classes from static libraries
CocoaPods Troubleshooting


Windows 8.1 upgrade – odd behavior

For the past week (possibly more), my laptop has been taking a very long time to shut down. By itself, that is an odd thing to be complaining about, but I’m the kind of person who likes looking at details and in this specific case, just have a tendency to push the “off” switch on the power socket when I’m done with my system. Wanting to save a bit of time I decided to search up on the matter. Here are a few links that I found;

Clearly, I’m not the only one facing this issue. But complaining about windows happens so often, that the result is not that surprising. No, what I found surprising (the point of this post!) and perplexing was one of the suggestions I came across – to make a new user account.

I had to pause for a few moments when I saw that. It had to be a joke, right? But reading further on the thread (not sure if its among the lot above), the poster was serious. He(/She) claimed that it was due to some corruption that happens to a user’s account when upgrading and make a new user from scratch solves the matter. Between the other suggestions of rolling back drives, or even the OS update itself, this was a relatively cheap suggestion and I gave it a shot.

I opened up the control panel, made a new “temp” user and gave him administrative privileges. Logged out of my current user-profile, logged into the new one and tried turning off my system. It still took a long time to switch off. Huh. So much for that theory. Still, I wanted to try another experiment. I rebooted into my laptop and directly logged into the “temp” user without touching my original account. Turning off my laptop this time was a lot faster. In fact, it is comparable to how things were for me pre-win8.1 update.

What is causing this behavior? I wish I knew how Microsoft handled user profiles, but since I don’t work there, it’s not in my hands. What IS in my hands, is the rather bothersome task of moving my files to the new user account – and deleting the old one afterwards. At the time of typing, I’m actually finished with the move, but am going to keep the other account around for a bit longer, in case I forgot something. Will probably delete it from my system after a month (Why leave  an unused account on the system, anyway?)

The new account also revealed a few odd quirks with Windows8.1. The text in Google’s chrome browser for instance became rather blurred. Let me try pasting a screenshot;


On seeing this, I began to wonder if this was Microsoft’s latest attempt at getting people to use Internet Explorer again. Conspiracy theory or not, I needed to fix this and went to the internet (blurry browser in tow) to find answers. It took me awhile, but I finally narrowed down the problem to a Display Scaling setting. Let me describe the answer first and then come round to proposing an explanation. You need to find the location where the chrome executable is stored. Open up Explorer and navigate to C: > Program Files (x86) > Google > Chrome > Application > chrome.exe. Right-click the executable and select properties. Go over to the ‘compatibility’ tab and check the “Disable display scaling on high DPI settings” option (like figure below).


On restarting chrome this is what I got,


I’m not sure if you can see the difference with the screenshots, but to my eyes it’s a whole lot better. Oddest thing, is that this isn’t a chrome-only problem. I’m facing the same issue (and solution) with a couple of other applications too – Keepass being the most recent example. Weird.

Asynchronous programming – breaking the illusions of blocking code

Over the past couple of weeks, I’ve been forced to confront the asynchronous programming style. Not out of choice, but because it was the only interface provided by a third-party library that needed to be integrated. Now before I begin, let me stress that asynchronous does not mean parallel programming. If this were parallel programming, I could try wrapping the offending code in some special context and most problems would go away. No, asynchronous is actually single threaded execution pretending to be parallel.

Let’s start off with a simple code snippet to understand this. Have a look at the pseudo-code below;

for (i = 0; i < 3; i++ {
    print("current loop=" i);

The output of the above program would look like this;

current loop=0
current loop=1
current loop=2

For the most part, the flow of execution is straight-forward enough, isn’t it? Now, remember that 3rd-party library that I needed to work with? Well, that was an asynchronous call that returned a value that needed to be used inside the for-loop. Naively, the following attempt at integration was made;

for (i = 0; i < 3; i++ {
    async_print("current loop=" i);

The result baffled me. Here’s what I got;

current loop=3
current loop=3
current loop=3

Which didn’t make any goddamn sense! … at first. I spent a considerable amount of time searching for answers. In the end, it came. The problem was that I didn’t quite understand the flow of program execution.

Coming from a synchronous programming, I assumed that asynchronous calls were some fancy way of parallel programming. They aren’t. I also assumed that the async function call would be blocking (i.e. the program would wait till the function/method finished executing). That wasn’t quite the correct answer either.

You see, what happens with asynchronous statements (at least the ones I’ve encountered), are something what might be called as “deferred execution”. When an asynchronous statement is reached, the control flow does not execute it. Instead, the statement is put on a queue to be executed later. Once the current context of program statements are finished, items in the queue are taken out in a FIFO manner and executed.

So, how does this explain the earlier for-loop? Within each loop, when the async call is made, its put on the queue. Now, when will the loop be over with? When the value of i is equal to 3. It is in this kind of context that the async calls get serviced. So, even though they are called three times, the value of i for each of those calls is 3 – thus producing our strange result.

I’m probably missing out some important details, but from an understanding point of view, this know-how was critical to help me solve my problem. The solution I resorted to was recursion. Here’s how the ‘fixed’ pseudo-code looks like;

i = 0;
function (i)
   async_print("current loop=" i );
   if (i < 3)
      call function (i);

Things might seem a bit stretched out, but the key concept that needs to be understood, is that now every call to function() happens in a different context. This means that even if the code flows by skipping the async_print() function initially, when it returns to service the call, the context to which it returns is the same. Thus giving us this output;

current loop=0
current loop=1
current loop=2

Hmm… this would probably be better if I could demonstrate some actual code instead of this pseudo-stuff. Let me see if I can rig up something …

My first deep-fried dishes!

About 4 or 6 months ago, I moved into a personal apartment and began living on my own. This meant learning a new skill – cooking. Now, in-spite of having lived for over 20 years, my character never invested any level-up points to the “cooking” skill. Barring a certain incident, … it might have been about … 7 or 18 years ago when the cauldrons in the kitchen first beckoned me. After some trial-and-error, “instant noodles” became a recipe I could safely cook on my own. Which was all there was to my “cooking” skill for many years to come.

A unique opportunity presented itself to me as I began to study the prospect of living alone. It could be the chance of a lifetime for me to answer the age-old question of; “Can a man live on bread alone?”. Not knowing how to make bread, the question had to be … modified … to fit my situation. The new age-old question became; “Can a man live on instant noodles alone?” Answering this, would forever carve my name in the annals of Philosophy! And I wouldn’t even need to eat the same food everyday either. With so many brands of instant noodles in today’s market, it would be child’s play if I wanted a change of taste. Taking the idea even further, it wouldn’t be just taste, but the cooking formula as well! Undercooked? Overcooked? Anything in-between? A golden opportunity, if there ever was one!

Unfortunately, mistress common sense barged into the room, grabbed me by the neck, threw me on the bed of reason, stripped me of all the above philosophical ideas and proceeded to have her way with me. A guy can’t really say no when confronted in such a manner, so I asked Lady insanity to hide under the bed and wait until we could get some extended quality time together. Which would probably happen sometime in the unknown future, but fortunately insanity is very patient.


The drama aside, I needed another way to feed myself to appease mistress common sense. As in any good RPG, the answer was obvious – my character would need to level up and invest a few skill points in cooking. Again, as with any good RPG this means to ask the local expert for advice. There’s only one such expert I know of – my Mother.

Usually, I wouldn’t have any issues with approaching my Mom for anything. We like to consider ourselves as a nice loving family and keep no secrets between each other. At least, that’s the official story. I used to own a personal stash of internet porn which went missing and it’s too embarrassing to ask family for help in searching for it, but … that’s another matter entirely.

Coming back to the issue of cooking, there is another … aspect … which I haven’t mentioned so far. In my 20+ (or so) trips around the sun thus far, I have subjugated my family to the horrors of what anyone with 0 skill points invested in cooking would produce – burnt, crisp, charcoal quality toast was fed to my only brother; instant noodles were cooked for so many consecutive nights that both my parents grew sick; a nameless something was created one fine day and fed to my cat. I could go on-and-on with a more examples, but the end result is that my Mother became very leery of permitting me to do anything associated with cooking in the kitchen. There have been times when she would get a certain, strange look in her eyes as I approached the stove.

It wasn’t a hopeless situation. I was still her child after-all, and so, did what any other child would do when wanting something from their parent. No, not bawling tears – it doesn’t work against my parents and besides, that’s a baby’s tactic. We’re not looking to get breast-fed here people! Oh no, it was the other thing. Anyone with a loving parent knows what I’m talking about. It’s too embarrassing to mention.

Fortunately, it worked and I convinced my Mother to teach me cooking. The first few attempts were … well … not-so-great. Eventually, after weeks of practice (and eating my own gunk) I was able to make rice!

The rice I make can’t really be called good or even tasty, but at the very least it can be considered edible. With so few points invested in my cooking skill, a full course gourmet meal is out of the question, but I am capable of making simple dishes and other small items. Which brings us back to the topic of this post. Considering the state that I was in, my Mother gifted me with the following piece of advice – “do NOT attempt to deep-fry anything without someone around to help you”.

So like any good cooking student, without anyone around to help me in-case things go wrong, I decided to try out the dark arts of deep frying anyway. Now, I’m not stupid enough to just walk into the kitchen, dump oil in a pan and set it ablaze (Though, now that I mention it, think it would be fun to try out. Just once!). Instead, I decided to approach the matter as an engineering problem. Those are a variety of puzzles that I’m pretty good at solving and, surprisingly enough, the tactic helped put things in a better perspective.

When solving an engineering problem, the first thing to do is research – books, youtube cooking videos and what-not. You can’t solve a problem if you don’t understand it, which meant that I wouldn’t even start until I had all the theory firmly ingrained in my head! Next is the matter of preparing the workshop and tools. Or in this case, the kitchen, ingredients and utensils. The local supermarket was most helpful in this endeavor. This, being a new kind of problem, meant that the solution would have to be as simple as possible. What does that mean from a cooking perspective? It means that only those “ready-to-cook” items from the supermarket’s frozen section would be tried out. I decided to go with a packet of chicken fingers and french fries. Once all that was setup, I was ready to begin my first deep-fry style cooking!

First, a non-stick pan was taken out and about 400ml of vegetable oil was poured into it. Next, the induction cooker was set to “deep fry” mode. It was fascinating to watch as the oil warmed itself in the pan and began flowing around. The flow isn’t easily visible and I had to turn & squint my eyes from the side of the pan to see it, but once the oil appeared to be … well, hot, it was time to start the main show!

A few frozen french fries were taken out of their plastic bag and slowly dipped into the hot oil. This had to be done very carefully. The fries started sizzling as soon as they touched the oil, which in turn caused some of the oil to leap out onto my bare hands. I think it was a minor miracle that I didn’t make a bigger mess of the situation. After that, it was a waiting game. Eventually the fries in the pan changed their color to the tasty golden-brown shade. Using my plastic spatula, I rinsed out the cooked fries and added in the next batch. This second set cooked a lot faster. From then on, it was a fairly repetitive procedure. Occasionally, a bit of salt would be added to the cooked fires. Not sure how long it took but in the end, I think the results speak for themselves. Here’s a picture of what I made,

Not bad for a first try, even if I do say so myself!

Not bad for a first try, even if I do say so myself!

Up next were the chicken fingers. This too was cooked in a similar fashion. Oddly enough, they cooked a lot faster than expected. Perhaps it was because I had already used the oil to cook the above fries, but first few chicken pieces that were put in? They got over-cooked. After playing around with the heat settings on my cooker, the problem was no more. Here’s a picture of my second deep-fry dish,

Can you guess which were my first batch? (hint: the 3 black ones on the left)

Can you guess which were my first batch? (hint: the 3 black ones on the left)


Let me tell you folks, it’s a wonderful feeling to know that you successfully did something others more experienced than you, told you not to. At this point all that was left to do, was to settle down in front of my computer, play a video and enjoy the meal!

Speaking of enjoying the meal, I decided to do it with the show We Without Wings. Surely, something with such a nice name and cute cover picture would be a wonderful romance/drama story, right? Sadly, such was not the case. The show is so full of … questionable … fan-service, that I could neither enjoy the plot (if there was one) or the fan-service itself. Now, I like the latter as much as most folks, but this particular show does it with such an arrogant “In YOUR Face” attitude that you can’t help but cringe in agony!

Which in retrospect, is probably a good thing as it prevented me from over-eating. Tells you a lot about the show, doesn’t it? Seriously folks, do NOT watch it!

Especially, if you are eating something you cooked yourself. The food deserves better.

Anime review “Mahou Sensou (Ep.01)”

I got a request to try and review the first episode of Mahou Sensou. Why did I pick it up? It’s because I’ve never done an anime review before – which means something new to try out! And if it turns out good, I might even do more. Alright, enough blabbering. Let’s see what the synopsys says (copy-pasting this from myanimelist),

In this modern magic action story, Takeshi Nanase is an ordinary high school boy who has a somewhat dark past. Due to certain circumstances, he formed a “fake” couple with his childhood friend Kurumi Isoshima, but otherwise, he lives a normal life. However, one day, he comes across a girl named Mui Aiba, in a uniform he has never seen before, collapsed on the school campus. This encounters changes Takeshi’s destiny completely. Mui tells Takeshi that she is a magician, and she apologizes, for she turned Takeshi into a magician, too. What Takeshi once knew as one world is actually two—the world where magicians live and the world where humans live.
Before we start with the actual show, lets talk about what we might be able to expect from the above paragraph. A hero with a dark past? Aren’t most of them like that? The very first such “hero” that comes to my mind is Batman. And for some odd reason I’m also thinking of Kirito from SAO. At best the latter only has a dark cloak, but he’s presented to the viewer as “the mysterious bad-ass who nobody knows about, but has a heart of gold”. Then we come to the next bit – the guy is in some kind of “pretend” relationship with his childhood friend. I don’t think I’ve EVER seen an anime where they pull this off well. Unless it’s part of some gag, what usually happens is that one (or in some situations both) parties in the relationship grow actual feelings for the other. It’s a really weird kind of romantic tension – everyone else thinks that the two of you are going out, but there is this invisible barrier preventing either party from taking the first step. Bring in another romantic interest and you have all the ingredients for a love comedy. And finally, our hero meets some ‘mysterious’ girl and gains magic powers? Does this have anything to do with his own “mysteriously dark” past? Let’s find out!

Fanfiction review “FateScrewed-Up”

And time for another fan-fiction review. This time it’s a cross-over story between Harry Potter and Fate/Stay Night. What’s disappointing is the plot. Here’s how it goes – Harry, after gaining all three Hallows, becomes some God-like entity who doesn’t die, but re-incarnates … as a girl. That by itself, is just silly and in the right author’s hands can be made into a brilliant plot. As for this author? It gets worse. He gender-bends Shirou. Yeah, truly a WTF kind-of moment. Here’s the link to the story,

FateScrewed-Up by Magician of Blue

This time, instead of just writing the review in my blog, I decided to put it up on FFN as well. In the general interest of laziness, I’m going to copy-paste it here –

Continue reading

Fanfiction review “The Monster Lord”

Instead of reviewing the story by myself, I’ve decided to ask for assistance from an acquaintance. A second opinion is usually helpful and considering that the intent of these reviews is to be critically constructive, it should be a good idea. Here’s the link to the story (WARNING: spoilers ahead!),

The Monster Lord by MadHat886

It’s a Ranma 1/2 crossover fanfic fusing the hentai games “Monster Girl Quest” and “Violated Hero”.

You know, perhaps I should just do this one by myself as usual. The whole second opinion thing might be better left for another kind of story  and … ah, dammit. I’m here. It’s the place where my acquaintance lives. Amusingly enough, he freeloads in a church,

The church

And I’m coming here to talk about hentai. I think I forgot my common-sense somewhere… Continue reading