A little trip through dependencies and accompanying difficulties
Tags: haxe, developer, motivation, programming
Published: 2020-04-17 10:10:05

It’s story where a little task causes an interesting trip through several open source libraries and programming languages. I’d like to mention that the text below is not the nagging about others’ or my code quality but just a yarn about how things are highly connected and how challenging and fun unraveling these links and finally solving a problem.

I’ve got an iOS app - [Moulinella](https://apps.apple.com/by/app/moulinella/id1406645161). It’s a cross-platform app written on [Haxe](https://haxe.org) using [OpenFL](https://openfl.org) and [JiveUI](https://github.com/jiveui/jive) frameworks and run on iOS, Android and [in the web](https://www.moulinella.com). I needed to support a document opening feature. So other apps could send specific files to my app.

First of all I’d found [a great tutorial about document sharing on iOS](https://www.raywenderlich.com/813044-uiactivityviewcontroller-tutorial-sharing-data). There was some changes to XCode project but using OpenFL’s templates I did in the past. It was OK. The main code changes were related to [UIApplicationDelegate](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application?language=objc). This part was several layers deeper than my app’s code. I hoped that OpenFL team passed this feature closer to me. It was a bit hard to find but they did it. [Singmajesty mentioned on the forum](https://community.openfl.org/t/ios-appdelegate-application-openurl-options-not-being-called/9196/3) that there is lime.ui.Window.onDropFile event already, thanks to [SDL library](http://www.libsdl.org). This event provides an URL of a file that is passed to an app on iOS. Great! Here we can see two more layers: 

* [Lime](https://github.com/haxelime/lime) - a foundational Haxe framework for cross-platform development. It provides the wrapper code for different platforms so it’s written on Haxe, C++, Objective-C and Java.  It’s a base for OpenFL.

* [SDL](http://www.libsdl.org) - Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It’s base for Lime and written mostly on C;

**Try #1:** Code was written, compiled, run but didn’t work well! Nothing happened.

Oh, I forgot that I’d replaced SDL’s UIApplicationDelegate by mine already. It was needed to implement third party authentication: Facebook and VK. So [the code related to the onDropFile event](https://github.com/native-toolkit/sdl/blob/370d05558c31570e34c642303705a66a9d0d1547/src/video/uikit/SDL_uikitappdelegate.m#L493-L521) just wasn’t run. OK, let’s [call SDL’s code from mine](https://github.com/ngrebenshikov/extension-vk/blob/35fddff529fa919f7d21f8118f5b26f5eaa14a26/sample-include/project/SDLUIKitDelegate.mm#L30). So I’d just added a small piece of Objective-C code. 

**Try #2:** Code was written, compiled. I’d got an error from the linker - my code couldn’t find symbols for SDL’s code.

Maybe the Lime library compiled badly (I’ve got the latest dev version of Lime) and doesn’t have corresponding symbols. Let’s compile Lime. Hm! Lime can not be compiled! I definitely did something wrong. After investigation the wrong part was an updating [hxcpp library](https://github.com/HaxeFoundation/hxcpp) to the latest version. It emerged that the Lime dependents on some part of Hxcpp [that was deleted as unused](https://github.com/HaxeFoundation/hxcpp/commit/e431d92809a521444594010cbe0dce4b836f6f18). I had a hack and reverted that changes for me for now and [informed the Lime team](https://github.com/haxelime/lime/issues/1393) about an issue.

**Try #3:** Lime compiled. But I still got an error from the linker - my code couldn’t find symbols for SDL’s code.

Here I have to say that I’m not experienced C++ developer so didn’t find the cause earlier. After a quarter of an hour or more of googling why C++ linked could find symbols I learned that if the symbols were written on C it needs to link them differently (using [extern "C" linkage-specification](https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c)). So I’ve added [the wrapper to my code](https://github.com/ngrebenshikov/extension-vk/blob/35fddff529fa919f7d21f8118f5b26f5eaa14a26/sample-include/project/SDLUIKitDelegate.mm#L6-L9).

**Try #4:** Code was written, compiled, run and worked great!

I was extremely happy that the problem was finished successfully! 

Now I’m thinking how I should perceive described situation. Firstly, I was losing time not doing something valuable for my customers but just fixing my faults. Secondly, it was an opportunity to understand better how the app works on the different layers and increase the code quality. Finally, the software is a complex thing and it’s tough to deal with it. 

When I spent several hours and went through several layers of the framework code I had a moment of satisfaction thinking how big and complex the modern software is but we (developers) can handle all this information structure. At that moment I realized how much I love and proud of my profession because it can give this kind of emotions.

I hope you feel the same.