How to Build an iOS Toolchain for Linux (Debian 7)
After jailbreaking an iPhone I discovered it was a device that had more behind it than just a dumbed down user interface. I had unlocked a unix operating system with a complete package manager (cydia/apt) and development tools to boot. This was pretty cool, I could even compile programs for iPhone on an iPhone.
Cool, yes. But perhaps not very practical for developing complex applications. For that you need a mac right?
Well... no. You don't.
Look at the tools under the hood and you'll see it is a mostly open source stack powered by clang, llvm and a custom linker for the darwin/mach kernel. This article will show you how to build an iOS toolchain for Linux Debian 7 (Wheezy). It is basically a fork of the instructions on the iOS Clang Toolchain installation page but has been updated for Debian 7 and includes a few little patches and tweaks here and there.How to Build an iOS Toolchain for Linux (Debian 7)
Clang and llvm compile C, C++ and Objective-C to machine code. They support ARM targets out of the box so we use the upstream versions. We're using the 3.4 version of llvm because some issues have been reported with the 3.5 version.
The GNU linker cannot create binaries for iOS, so we have to build the Apple linker which is made easier by the fork maintained in the toolchain project.
Note this installs a new linker (ld) in /usr/bin. If you're building C apps for your local system you'll have to restore the old linker by reversing those last two commands. The two linkers are not compatible.
These tools come from the toolchain project (again) and include utilities to make builds easier such as converting xcode projects to Makefiles and configuring the location of the SDK.
*** getLocalizedStringFromFile.cpp~ 2015-04-02 04:45:39.309837816 +0530 --- getLocalizedStringFromFile.cpp 2015-04-02 04:45:11.525700021 +0530 *************** *** 113,115 **** clang::HeaderSearch headerSearch(headerSearchOptions, - fileManager, *pDiagnosticsEngine, --- 113,115 ---- clang::HeaderSearch headerSearch(headerSearchOptions, + sourceManager, *pDiagnosticsEngine, *************** *** 129,134 **** false); - clang::HeaderSearch headerSearch(fileManager, *pDiagnosticsEngine, languageOptions, - pTargetInfo); ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptions, pTargetInfo->getTriple()); --- 129,134 ---- false); + clang::HeaderSearch headerSearch(fileManager);/*, *pDiagnosticsEngine, languageOptions, + pTargetInfo);*/ ApplyHeaderSearchOptions(headerSearch, headerSearchOptions, languageOptions, pTargetInfo->getTriple());
The patch above is just to get it to compile and may break something in that utility (ios-genLocalization). It is necessary because the llvm API has been changing frequently.
You're now ready to build apps for iOS, but chances are you will be wanting to use libraries from the iOS SDK, so you might as well download it now. The SDK ships with xcode and is difficult to extract (thanks Apple!) but there are some pre-extracted versions available online.
ios-createProject includes a sample HelloWorld app you can build with your new tools. If all goes well, it'll be running on your iPhone in a couple of minutes :) You will need OpenSSH installed on your iPhone, which can be installed with cydia or apt-get.
Have fun, let me know how you go in the comments below.
You're a software developer, you're used to this shite right? Your first port of call is probably the GitHub issues for the toolchain project. If you post some patches in the comments below though I'll add them here to help people along a bit.
# ios-clang -c -objc-arc -fblocks -g0 -O2 -I"." HelloWorldApplication.m -o HelloWorldApplication.o terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr
The above error is caused by ios-clang being unable to find the cctools binaries. Make sure you have /usr/local/bin on your PATH and check the binaries have been installed (they all start with arm-apple-darwin11.
invalid option for ld: -dynamic
This error occurs when you try to link using the GNU linker (or some other linker). Make sure you symlink /usr/local/bin/arm-apple-darwin11-ld to /usr/bin/ld.
I suppose I am a problem solver. Either that, or I am an organic carbon-based life form whose function is to convert oxygen into carbon dioxide. You could go either way on that. I'm into languages and stuff. I recently published my first book. It's okay, I guess. Lots of sex and drama--plus it's a true story. Let's see... What else? I like reading, swimming, playing music, and annoying Seda. KAPOW!