Reputation: 305
I am following a basic "Hello World" example from a textbook whose purpose is to create and cross-compile a simple command line program on a MacOS with Xcode and then run it on a jailbroken iPad. I use the arm-apple-darwin10-llvm-gcc-4.2 cross compiler on MacOS 10.6.8 from an Xcode 4.2 install. The sample code is:
#include <stdio.h>
main ( ) {
printf("Hello, World!");
}
and the compile I am attempting is this:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -o hello hello.c -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
This generates an object when inspected with the file command displays:
$ file hello
hello: Mach-O executable arm
Ok. So far so good. I should be able to copy this to my iPad and use ldid.
However it fails:
MyiPad: /Applications root# ldid -S hello
codesign_allocate: object: hello malformed object (unknown load command 8)
util/ldid.cpp(582): _assert(78:WEXITSTATUS(status) == 0)
In addition, if I run strings back on the MacOS, it displays the same error.
$ strings hello
strings: object: hello malformed object (unknown load command 8)
My belief is that there is something wrong with the configuration or setup of Xcode. Or I have not had enough coffee yet. But this is a textbook example so clearly I am missing something in my setup. I have also tried setting up the iPhoneOS5.1.sdk with the platforms, sdk, and Sim directory as per iOS 5.1 with Xcode 4.2 and retina in iPad 3
Any pointers greatly appreciated.
Upvotes: 0
Views: 1940
Reputation: 947
Instead of creating your own certificate, check out ldid: http://iphonedevwiki.net/index.php/Theos/Getting_Started
Just run ldid -S binary
on your host machine (after either building it from source or downloading it drop Dropbox) and it'll run on jailbroken iOS 5.1.
Upvotes: 0
Reputation: 305
Yes. I can answer my own question...or a least most of it.
First of all, the strings command on MacOS is a red herring. I thought that told me something was wrong with the binary. But I could use otools and nm on it. So, ignore strings. Unless someone wants to answer that conundrum I wont worry about it. Its still curious.
So fundamentally, ldid was the problem as explained here by Patrick Toomey. Short story, ldid uses codesign_allocate which does not appear to support the Load Command that the arm-apple cross-compiler is adding.
My solution was to create my own self-signed certificate on MacOS using keychain access and use /usr/bin/codesign to sign the binary with it.
The details: $ export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate $ codesign -fs "certname" programname
Copy it to the iPad and gasp it runs.
Upvotes: 2