0

I use ssh to iphone, and can compile console apps on iphone using clang or gcc. But now how can I link against UIKit? Compiler finds headers and stuck at linking.

what args I should pass to clang? How can I check if I have the required static/shared libs? what exactly are the files to link against?

the example program:

#import <stdio.h>
#import <UIKit/UIView.h>

int main() {
        UIView *U = [UIView alloc];
        printf("OK\n");
        return 0;
}

Here is the command line and error:

$ clang main.m
Undefined symbols:
  "_OBJC_CLASS_$_UIView", referenced from:
      __objc_classrefs__DATA@0 in main-2RgCk6.o
  "_objc_msgSend", referenced from:
      _main in main-2RgCk6.o
ld: symbol(s) not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

extra info:

$ uname -a
Darwin devphone-teki-iPhone 13.0.0 Darwin Kernel Version 13.0.0: Sun Dec 16 19:58:44 PST 2012; root:xnu-2107.7.55~11/RELEASE_ARM_S5L8940X iPhone4,1 arm N94AP Darwin

$ clang --version
clang version 3.1 (trunk 152547)
Target: arm-apple-darwin13.0.0
Thread model: posix
exebook
  • 32,014
  • 33
  • 141
  • 226
  • why you want to compile GUI app on your iPhone?? in order to do so, you need to copy all the related frameworks and headers to your phone and use `--framework UIKit` to include them in linking process – Bryan Chen Feb 26 '13 at 10:37
  • I need to compile it to get binary file and run it. and why you suggest "copy all the related frameworks and headers" if my question is what particular files I need? it's like I ask you someone's phone number and you reply "you need to use dial pad to call him". – exebook Feb 26 '13 at 10:59
  • your phone is not really the idea device to do such work... and to be honest, I am not sure what files are need so this is not an answer. but I know you need to link the binary to CoreFoundation and UIKit – Bryan Chen Feb 26 '13 at 22:29
  • What's wrong with compiling on iphone/ipad? It is *nix device, you have all tools available. "Getting it to appstore" is another story, not every programer must think about it. – exebook Feb 27 '13 at 08:09
  • that's nothing really wrong, but i don't understand why you choose iphone/ipad to compile. it is so limited. – Bryan Chen Feb 27 '13 at 08:53

1 Answers1

1

Answer my question after successful compilation.

You need to use apt to install clang gcc p7zip then find sdk 3

iphone_sdk_3.1.3_with_xcode_3.1.4__leopard__9m2809a.dmg 

Extract to get

iPhoneSDK3_1_2.pkg

Then extract it again to -> ~/sdk

(You may need to use 7z many times to extract deeper), you will get this:

$ ls ~/sdk
Developer/  Entitlements.plist  ResourceRules.plist  SDKSettings.plist  System/   usr/

Then compile like this

clang main.m -o main -isysroot ~/sdk/ \
-miphoneos-version-min=2 -L~/sdk/usr/lib -lobjc \
-framework UIKit \
-framework Foundation

Once you get 'main' copy it to your app folder and owerwrite previously installed app.

cp main /var/stash/Applications.Q6ABC7/myApp.app/myapp
kill myapp

Now you can click icon of your app and see it works.

exebook
  • 32,014
  • 33
  • 141
  • 226
  • by the way this might be useful for someone, -framework seems to be apple own invented extension to clang that basically behaves like smarter -l. normally gcc/clang will link to .o, .a or .so(dylib on iphone) files. -framework seems to link to directory. someone may know more about it. – exebook Feb 27 '13 at 08:25