IPhone 3.1.2 development environment-Linux platform

Source: Internet
Author: User
Tags posix unpack

I. Introduction
Some time ago I saw the iPhone os4.0 Preview Video released by Apple, and the iPhone finally planned to support multiple tasks, especially the presentation of Skype software in the Preview Video.
Generally, to be a regular iPhone app developer, you should prepare at least three things:
(1) An Apple Computer
It can be a Mac Book or a Mac Mini. Most domestic "frugal" companies choose Mac Mini (the current price is about 5 K), and then have a cheap display; for Mac Books, the cheapest is tens of thousands. No way. The integrated development environment of the iPhone can only run on Apple's computer.
(2) One iPhone
The best is the iPhone 3gs (the current price is about K). Of course, the iPhone 3G can also be used, but from the developer's perspective, it is better to have better performance (it is not guaranteed that every developer can write highly efficient code as soon as they get started with iPhone development ).
(3) One Developer authorization
Register a developer ID on the Apple developer website and apply for developer authorization for this ID (you need to pay $99 every year. Note that the unit is USD. You need to consider the exchange rate problem ).
After that, you can download the iPhone SDK, use xcode to develop an application, test the real machine, and then send it to the App Store for release. Finally, you can check your account every day. Although there have been rumors on the Internet that iPhone users are "stupid and have a lot of money" and can make money by doing anything, after some observation, iPhone users emphasize creativity, fashion, and personality, and are very picky about the smoothness of operations (mainly because Apple "Spoiled" these users ). Therefore, it is absolutely impossible to make money by doing anything in the app store, the result of doing something "casually" is that Apple can make that poor $99 (of course, it also includes the income from Mac computers and iPhones sold to developers ), in the end, developers are still empty-handed.
Of course, the above are for developers who want to make money through the App Store. I personally have always been disgusted with Apple's money collection from developers (likewise, I would like to discuss the behavior that Symbian sign will cost 170 euros ). Therefore, when doing some research and experiments, we generally start from the most economical point of view. So I decided to build a simple development environment on my office computer (for a long time, I only had Linux on my office computer), so I could play home brew in my spare time. (I confirmed the famous saying: do not work hard, the boss is doing it ).
2. Preparations
1. Basic Principles
The iPhone 2g/3g cpu uses Samsung's, while the 3gs CPU uses s5pc100, which is generally an ARM architecture. In principle, there should be no difference between iPhone development and other embedded device development. Compile the code with a Compilation Program that supports the arm instruction set, generate a file that can be run in the arm system (for example, generate a file that can be run on the ARM platform on the PC, which is also called "cross compilation ). Next, we will build such a cross-compilation environment under the Linux platform. We should be able to build the environment smoothly (depending on personal creation, haha ).
2. Think about the right thing before you start
Disadvantages:
(1) software developed by sdks under Linux can only be used for iPhone phones that have been jailbroken by jailbreak.
(2) It does not support iPhone simulators, single-step debugging, real-machine debugging, and IDE integrated development environments.
(3) Currently, the maximum version can only support iPhone SDK 3.1.2 (it is estimated that 3.2 will not be available in the future, and 4.0 will be supported ).
(4) The Environment configuration process is cumbersome and time-consuming. Even if you follow this article, it may fail ("even if you are yourself, it may not succeed ?!", Haha ).
(5) Running the application developed by this SDK may make the iPhone brick (in fact, as long as jailbreak is used, it may change bricks ).
Advantages:
(1) You do not need to pay $99 for developer permissions.
(2) You do not need to buy an Apple Computer.
(3 )... It can be used to consume time (not knowing this is not an advantage ).
If you still want to install the above-mentioned defects, follow the steps below:
3. Preparations before the start
Even the computer is ThinkPad sl400.
System: slackware 13.0
Kernel version: Linux Wayne 2.6.29.6-smp-Wayne #1 SMP Thu mar 18 20:00:29 HKT 2010 i686 Intel (r) core (TM) 2 Duo CPU t5870 @ 2.00 GHz genuineintel GNU/Linux
GCC version:
Reading specs from/usr/lib/GCC/i486-slackware-linux/4.3.3/specs
Target: i486-slackware-linux
Configured :.. /gcc-4.3.3/configure -- prefix =/usr -- libdir =/usr/lib -- enable-shared -- enable-Bootstrap -- enable-languages ages = Ada, C, C ++, Fortran, java, objc -- enable-threads = POSIX -- enable-checking = release -- With-system-zlib -- disable-libunwind-exceptions -- enable-_ cxa_atexit -- enable-libssp -- With-GNU- LD -- verbose -- With-arch = i486 -- target = i486-slackware-linux -- Build = i486-slackware-linux -- Host = i486-slackware-linux
Thread model: POSIX
GCC version 4.3.3 (GCC)
The tested mobile phone is the iPhone 3gs that has been used by jailbreak. The system is iPhone OS 3.1.2.
Theoretically, the program developed in the following way can also run on the iPhone 3G platform.
(1) download the iPhone SDK
This SDK must be the official SDK 3.1.2, as shown below:
Http://ipsw.info/iphone_sdk_3.1.2_with_xcode_3.2.1__snow_leopard__10m2003.dmg
It is very large, 2.5 GB. It needs to be downloaded for a whole day! (You can use it for free... I am sorry ...)
(2) download the firmware (firmware) of the iPhone 3G)
Note: It must be iPhone 3G, and 3gs firmware cannot.
(Fortunately, the developed software can run on both 3G and 3 GS! Apple's downward compatibility is doing a good job)
As follows:
Http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7265.20091008.Xsd32/iPhone1,2_3.1.2_7D11_Restore.ipsw
(3) download the tool chain script through SVN
Cd ~
Mkdir-P iphone_dev/toolchain
CD iphone_dev/toolchain
SVN checkout http://iphonedevonlinux.googlecode.com/svn/trunk ./
This script project is very small. If there is no problem with the network, it should be downloaded soon.
(4) download all files in the darwin-tools.list
This file can be found in the iphone_dev/toolchain Directory, which contains a long list of files.
You can use kget or wget to download these files.
(5) download and install the xar Tool
Http://xar.googlecode.com/files/xar-1.5.2.tar.gz
This tool is used to unpackage DMG files. This tool is not available on slackware by default, and can be directly installed through source code.
The above steps can be said to be the most time-consuming preparation of the iPhone application compiling environment in the Linux environment.
3. Let's get started (according to foreigners -- get our hands dirty)
For convenience, run the following command.
(1) enter the installation script directory
Cd ~ /Iphone_dev/toolchain
(2) create files directories and subdirectories
Mkdir-P files/{firmware, darwin_sources}
(3) copy the iPhone 3G firmware to the files/firmware directory.
CP ~ /Downloads/iphone1, 2_3.1.2_7d11_restore.ipsw./files/firmware/
(4) copy the iPhone SDK to the files directory.
CP ~ /Downloads/iphone_sdk_3.1.2_with_xcode_3.2.1 _ snow_leopard _ 10m2003. DMG./files/
(5) Copy all the files in the darwin-tools.list downloaded earlier to the darwin_sources directory
CP ~ /Downloads/* .tar.gz./files/darwin_sources/
(6) start to modify the toolchain. Sh script
We didn't need to modify this script, but due to some network harmony problems, a foreign wiki that provides decoding strings cannot be accessed, so we had to use this method to solve it.
Open the toolchain. Sh file in your favorite editor and find the following line:
If [-z "$ decryption_key_system"]; then
Echo "we need the decryption key for 'basename $ fw_restore_systemdisk '."
Echo "I'm going to try to fetch it from $ iphonewiki_key_url ...."
Then, in the preceding if [...]; then statement, the above statement (emphasize again that it is the above !) Add the following line: decryption_key_system = "encryption"
After modification, save and exit.
(7) start unpacking the header file
./Toolchain. Sh Headers
(8) start to unpack the firmware file
./Toolchain. Sh firmware
(9) start to unpack drawin_sources
./Toolchain. Sh darwin_sources
This process will be long and patient.
(10) The last step of compilation is related to success or failure.
./Toolchain. Sh build
(11) Error Handling
Ld: library not found for-lC
Collect2: LD returned 1 exit status
Make [3]: *** [libgcc_s.dylib] Error 1
....
Make [2]: *** [stmp-multilib] Error 2
Rm gcov. Pod fsf-funding.pod GFDL. Pod GPL. Pod CPP. Pod GCC. Pod
....
Make [1]: *** [All-GCC] Error 2
Make [1]: Leaving dir '/home/XXX/toolchain/bld/gcc-4.2-iphone'
Make: *** [all] Error 2
Run the following command:
CP./sdks/iphoneos3.1.2.sdk/usr/lib/libsystem. B. dylib./toolchain/bld/gcc-4.2-iphone/GCC/libc. dylib
Run the following command again:
./Toolchain. Sh build
If the following prompt is displayed, the environment is successfully set up.
It seems like the toolchain built!
PS:
Here is a reference to the above copy libc. the dylib command can be run. /toolchain. after the sh build command, wait for a moment. When it starts to compile, open a new terminal window, enter the toolchain directory, and then execute the copied command, the compilation is successful at one time.
(12) set Environment Variables
For this purpose, I only paste my configuration. You can modify and adjust it based on your Configuration:
Export Path =/home/Wayne/iphone_dev/toolchain/PRE/bin: $ path
You can save this setting in. bashrc or/etc/profile. These settings will not affect noise.
Iv. Test the compiling environment
1. Compile the program
This process is very simple, as long as you enter ~ The/iphone_dev/toolchain/apps directory shows two projects for testing:
Hellotoolchain and helloworldfirst. Helloworldfirst is a command line software. Even if it can be run on the iPhone, a hello World is output after a helloworldfirst is input on the terminal. The hellotoolchain supports the GUI interface, is a textview, so it is more convincing.
By default, there is a makefile under these two directories. This file should lack some definition of paths. If you are in trouble, you can directly use the even makefile (see the attachment in this article ), this is something that has been manually modified and also run on a real machine. Replace the makefile of the two original projects with the even makefile, and then execute make.
If no error is displayed during this process, congratulations! Your Linux platform SDK has been set up successfully.
2. Run the program on the real machine
Well, the next step is a more challenging job-running a program on a real iPhone. But before that, check whether the phone is correct. I used the jailbreak iPhone 3gs, used Blackrain for jailbreak, and installed OpenSSH, APT, and ldid using cydia + WiFi (I am too lazy to write this part. The iPhone jailbreak method, ).
One thing to mention is about ldid. This tool is used to sign binary files on the iPhone platform. Many people on the Internet are operating under the iPhone 3gs. This tool is not easy to use, however, after even real machine testing, this tool is completely correct.
I will briefly mention how to correctly install this tool:
(1) install a program named terminal through cydia, which is a virtual command line terminal.
(2) connect the iPhone to WiFi and then start the terminal.
(3) run the su command and enter the password (if you have never entered the password, the default password is "Alpine". We recommend that you change the password to a safer password) to obtain the root permission.
(4) run the following command: APT-Get install ldid
(5) After the command line interface prompts that the installation is successful, the installation is successful.
Well, we started to copy hellotoolchain to the/applications directory of the mobile phone.
(1) first check the IP address of the iPhone connected to wifi (if this does not happen, skip the occasional article .)
(2) run the following command in Linux:
Cd ~ /Iphone_dev/toolchain/apps/hellotoolchain
Make clean; make
SCP-RP./hellotoolchain. app root@192.168.0.2:/applications/
If the following output is displayed (do not forget to enter the password !) :
RSA key fingerprint is 33: BC: 25: 5A: A6: 3C: 21: 72: 5D: 84: 22: D4: 4b: 62: 43: 25.
Are you sure you want to continue connecting (Yes/No )? Yes
Warning: Permanently added '192. 168.0.2 '(RSA) to the list of known hosts.
Root@192.168.0.2's password:
Icon.png 100% 1073 1.1kb/s
Info. plist 100% 746 0.7kb/s
Hellotoolchain _ 100% 13kb 13.2kb/s 00:00
Hellotoolchain 100% 61 0.1kb/s
Indicates that the file is successfully uploaded.
(3) log on to the iPhone and sign the program.
SSH root@192.168.0.2 (enter root password)
CD/Applications
CD/hellotoolchain
Ldid-s hellotoolchain _ (Note: Here is hellotoolchain _, which must be underlined !)
Okay, so we are all ready!
A lot of people wonder, how can they not see the program icon on the iPhone desktop ?!
Run the following command:
Killall springboard
This command forces the iPhone desktop program to be killed, and the iPhone will automatically open the desktop again. At this time, you can see the icon of the test program.
There is a saying on the Internet that "there are pictures and pictures". I will show you on two pictures:

This is the version of the iPhone 3gs.

Well, the interface is very beautiful. You can see the "red, blue, green" Question mark icon (this is an icon that I changed manually, the original icon is white with three question marks ).

This is how the program runs. It is a simple text view.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.