Compiling Objective-C files into object files (.o)
I have been tasked to create object .o files for an iOS project in Xcode 4. I have tried the following command which works on NSObject classes
gcc -c implemtationfile.m
but if I try to run the command on a class inherited from UIViewController for example I get a ton of errors starting with
UIKit/UIKit.h: No such file or directory
Secondly, since there are multiple files in the project, is it possib开发者_如何学JAVAle to create one .o file for all source files?
Not surprised you've got errors.
You are trying to compile iOS code from OSX. If you invoke GCC from the terminal, you'll get the Mac OS X compiler.
Even if it can produce .o files, those object files are Mach-O object files, meaning they are compiled as object-files against the Mac OS X compiler tool-chain.
No iOS here. Your object files will have the Intel (x86) or PPC architecture. iPhone is ARM, so you're wasted.
You should be able to proceed ARM object files using the right GCC compiler tool-chain.
Something like:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.0.1
I haven't tested, but that's clear that you need to use the iPhone ARM version of GCC. Just invoking GCC will invoke the Mac OS X version (in /usr/bin/).
A compiler like GCC needs to be compiled for a host and a target architecture.
The host architecture is the architecture in which you will invoke the compiler. The target one is the architecture for which you'll build binaries, or object files.
So try to compile your code with the correct version of GCC, which suits the iPhone target architecture.
Also note that, if compiling against a framework, you should use the -framework
GCC argument.
精彩评论