这是一个非常简单的Objective-C控制台应用程序:
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
NSLog(@"Hello world!");
[pool drain];
return 0;
}
我在我的Mac上用gcc main.m -o main -ObjC -framework Foundation -framework CoreLocation
编译它。
我的苹果电脑上也安装了iOS软件开发工具包。如何修改此命令以编译相同的代码 on my computer,以便在(越狱的) iOS device上使用?
然后,我可以通过ssh传输可执行文件,并使用ldid
对其进行签名。
发布于 2011-09-20 00:13:33
假设你不是固守陈腐的老GCC,故意在我的项目中触发错误,以便进入Xcode将揭示所使用的命令行的位置,揭示了用于编译的以下内容:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -c
-x -c -arch armv6 -fmessage-length=0 --x诊断-打印-源-范围-信息-诊断-显示类别=id -fdiagnostics-parseable-fixits /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -Wno-trigraphs fpascal-armv6 -std=gnu99 -O0 -Wmissing-prototypes Wreturn-type -Wparentheses -Wswitch -Wno-unused参数-Wunused-变量-wunusus值-DDEBUG=1 -isysroot -isysroot-gdwarf-2 "-DIBOutlet=attribute((iboutlet))“"-DIBOutletCollection(ClassName)=attribute((iboutletcollection(ClassName)))”"-DIBAction=void)attribute((ibaction)“-miphoneos- -mthumb - -iquote =3.2版本记账文件-Ia -iquote标头列表更多标头包含路径-fpch- -Ian -Fpointer to -Fpointer to directory for debug files -include my prefix header -c AppDelegate.m -o AppDelegate.o
如果您拒绝使用Xcode,那么我想您至少可以减少关于Interface Builder outlets的内容。在我的项目中,为armv6而不是v7构建可能是一个错误。
然后,链接:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -isysroot -Lsomething -Fsomething -filelist a .LinkFileList -dead_strip -armv6--isysroot--Lsomething=3.2 -framework SystemConfiguration -framework UIKit -framework -framework CoreGraphics -o某种适当的东西
.LinkedFileList文件似乎只是一个目标文件列表,每行一个。Xcode在其中放入了每一个的完整路径,不过我猜相对路径是可以接受的。
我很欣赏这不是一个完整的答案,但希望它能有所帮助?
发布于 2012-02-22 23:57:04
对于简单的情况,这可能已经足够好了:
gcc -o output -Wall -std=c99 source.m -framework Foundation -lobjc
更新:
此命令不适用于iOS命令行应用程序-必须正确设置arch。目前我手头还没有iOS开发环境;也许-march标志会有所帮助。
请参阅可接受的答案。
发布于 2012-03-16 01:50:59
要在mac上编译iOS代码,您需要使用交叉编译器,即在英特尔平台上运行并能够生成ARM二进制代码的编译器。
Xcode确实提供了这样的交叉编译器。它位于(假设您使用的是从App Store分发的Xcode 4.3 )
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
对于简单的"hello world“类型的程序,我使用以下命令进行编译
alias c="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2"
c -o hello hello.c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/
https://stackoverflow.com/questions/7473246
复制相似问题