14

I want to compile my IOS appication from linux terminal(command line).... Is it possible to do so, if yes, then how?

saurabh
  • 259
  • 1
  • 3
  • 11

2 Answers2

15

Yes, it's possible.

At least you need:

  1. Assembler and Linker: cctools and ld64 from apple opensource.
  2. Compiler: Clang/LLVM
  3. SDK, include headers and libraries.
  4. Utilities: such as ldid codesign tool.

Step 1 : The compiler

Clang/llvm >= 3.2 is highly recommended and tested.

If you want to build clang/llvm from scratch, Please refer to this link to build a svn version for your linux distribution.

If your distribution already provides clang/llvm packages,make sure it is 3.2 release or above. Lower version may work but isn't tested.

for Ubuntu 13.04 and later, clang/llvm already provided in repos, please run:

$sudo apt-get install gcc g++ clang libclang-dev uuid-dev libssl-dev libpng12-dev libicu-dev bison flex libsqlite3-dev

to install some dev packages, other dev packages related to llvm/llvm-dev should be installed automatically.

Step 2 : The assembler and linker

The latest cctools-855 and ld64-236.3 had been ported from Apple opensource to linux. the porting process is a little bit complicated, also with a lot of codes modified for linux, let's just skip it.

please check out the codes from:

svn checkout http://ios-toolchain-based-on-clang-for-linux.googlecode.com/svn/trunk/cctools-porting

Build it:

$ sed -i 's/proz -k=20  --no-curses/wget/g' cctools-ld64.sh
$ ./cctools-ld64.sh
$ cd cctools-855-ld64-236.3
$
$ ./configure --target=arm-apple-darwin11 --prefix=/usr
$ make
$ make install

For Ubuntu 13.04, since the clang/llvm 3.2 package use a customized libraries/headers path. please setup CFLAGS and CXXFLAGS first before run configure.

$export CFLAGS="-I/usr/include/llvm-c-3.2"
$export CXXFLAGS="-I/usr/include/llvm-c-3.2"

Step 3: The iPhoneOS SDK.

The old iPhone SDK with ARC support extracted from xcode had been provided in Download Sections. You can directly download it and extract it to /usr/share

For iOS 4.2: https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iPhoneOS4.2.sdk.tar.xz

For iOS 5.0: https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iPhoneOS5.0.sdk.tar.xz

For iOS 6.0: https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iPhoneOS6.0.sdk.tar.xz

For other iOS versions, You may need follow these steps to get the SDK for your self.

Step 4: The utilities

iphonesdk-utils is a utility collection for iOS development, provides below utilities:

NOTE: (Some of them are collected from internet with some modifications.)

ldid : codesign tool, with armv7/armv7s support and other changes from orig version. it will be involked by ld64 after link complete. ios-clang-wrapper : automatically find SDK and construct proper compilation args. ios-switchsdk : switch sdk when multiple version of SDK exist. ios-pngcrush: png crush/de-crush tool, like Apple's pngcrush. ios-createProject : project templates ios-genLocalization : iOS app localization tool based on clang lexer. ios-plutil : plist compiler/decompiler. ios-xcbuild : convert xcode project to makefile, build xcode project directly under linux. Download the source tarball from: https://ios-toolchain-based-on-clang-for-linux.googlecode.com/files/iphonesdk-utils-2.0.tar.gz

Build and install it:

$./configure --prefix=/usr
$make
$make install

Build App

Now you can build and install your project simply doing:

$cd ProjectDir
$make
$make install IPHONE_IP=<your own device IP

Complete info you can find here — https://code.google.com/p/ios-toolchain-based-on-clang-for-linux/wiki/HowTo_en

barjomet
  • 477
  • 4
  • 7
  • Hi, is it necessary to have the DUNS number for this?? – saurabh Jan 22 '15 at 14:54
  • $./cctools-ld64.sh -- Doesn't seem to work, as this link inside this script has nothing(the link -- "http://www.opensource.apple.com/tarballs/cctools/cctools-839.tar.gz/") – saurabh Jan 22 '15 at 17:53
  • No, thats not a problem, there's archive by this URL (http://www.opensource.apple.com/tarballs/cctools/cctools-839.tar.gz). Try `sed -i 's/proz -k=20 --no-curses/wget/g' cctools-ld64.sh` before doing `./cctools-ld64.sh`. Thats working for me. I will also edit an answer. In case this wont work — what linux do you use? – barjomet Jan 22 '15 at 21:45
  • Hi, I tried out sed command to replace the text and the text did got replaced with it but still I get this message: ./cctools-ld64.sh: line 27: proz: command not found ./cctools-ld64.sh: line 28: md5sum: command not found – saurabh Jan 29 '15 at 09:53
  • `$ sed -i 's/proz -k=20 --no-curses/wget/g' cctools-ld64.sh` — that just means sed command didn't applied, try again. Or if you want, you can replace all `proz` calls with `wget` or `curl` using your hands. Of cause you need wget or curl to installed on your system. `./cctools-ld64.sh: line 28: md5sum: command not found` — you need to install md5sum, in most linux distros it's included in coreutils package or similar. – barjomet Jan 29 '15 at 11:40
  • Now I get this: Try `wget --help' for more options. md5sum: stat 'ld64-236.3.tar.gz': No such file or directory wget: invalid option -- '=' wget: invalid option -- '2' wget: invalid option -- '0' wget: unrecognized option '--no-curses' Usage: wget [OPTION]... [URL]... – saurabh Jan 29 '15 at 12:51
  • Okay, the script ran...but still I think a long way to go....after running autogen.sh I get this: ./autogen.sh: line 3: aclocal: command not found ./autogen.sh: line 4: autoconf: command not found ./autogen.sh: line 5: libtoolize: command not found ./autogen.sh: line 6: automake: command not found.... now I have to look for this...ahhh m banging my head .. – saurabh Jan 29 '15 at 12:59
  • What linux distro/version do you use? – barjomet Jan 29 '15 at 14:51
  • Stuck at one place:: "./configure --target=arm-apple-darwin11 --prefix=/usr" this works fine....but when I run "make" it says...make: *** No targets specified and no makefile found. Stop. – saurabh Jan 29 '15 at 14:51
  • 13.4.0 kernel... this is what I got from uname -r – saurabh Jan 29 '15 at 14:56
  • From gcc --version I got this : Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix – saurabh Jan 29 '15 at 15:05
  • You should read carefully what ./configure says, I checked it for you on my current work machine with Ubuntu — I've missed some dev libraries uuid-dev, libssl-dev, llvm-dev. but whe I've installed them — all runs just fine. – barjomet Jan 29 '15 at 16:43
  • Hi, I am trying to install the dev package via "brew install uuid-dev"..but it doesn't, how did you installed those, also if I have to install the dev packages explicitly then how is Xcode doing the compiling process?? – saurabh Jan 30 '15 at 09:05
  • I can't help with package installation until you know exactly your linux distribution/version — [read this](http://unix.stackexchange.com/questions/88644/how-to-check-os-and-version-using-linux-commmand). Possibly there is one of major package-tools like apt-get, yum, zypper on your system, you can try to find them. Or you can try to build uuid-dev by yourself — it's included in `git://git.debian.org/~lamont/util-linux.git` sources. But anyway, if you want set up stable, reliable cross-build toolchain — you must know the system you use. – barjomet Jan 30 '15 at 10:41
  • It is Darwin 13.4.0 x86_64 – saurabh Jan 30 '15 at 11:53
  • Ok, you working on mac os x Mavericks, there is no linux terminal in mac os. Your question is incorrect. You better read [this](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html) — you can build iOS projects using xCode commandline. – barjomet Jan 30 '15 at 12:06
  • Hi Barjomet, thanks you for all your help, though went into wrong direction but a knowledge is never wasted, I am marking your answer as correct and putting up another answer to this question--"In case of maverics.."....if you think that is right please mark the answer as right. I appreciate all your help. Thanks. – saurabh Jan 30 '15 at 13:51
  • SVN can not checkout: `svn: E160013: »/svn/trunk/cctools-porting«` – Grim Aug 02 '23 at 16:13
-4

The above solution given by Barjomet is correct incase if its not mavericks, but if it is Maverics then following is the solution:

1) Install the appropriate command line tool 2) for building :a)xcodebuild -list -project .xcodeproj b)- xcodebuild -scheme build

For detail reference you can refer the following link:

https://developer.apple.com/library/ios/technotes/tn2339/_index.html.

saurabh
  • 259
  • 1
  • 3
  • 11