If you want to learn OC but have no Mac computer classmate, you can try the following methods to solve
We use GNUstep to learn Objective-c
First step: Install the required software and build the environment
sudo apt-get install gnustepsudo apt-get Install Gnustep-devel
Step two: Write the first OC code
#import <foundation/foundation.h>int Main (int argc, const char * argv[]) {NSAutoreleasePool * pool = [Nsaut Oreleasepool alloc] init]; NSLog (@ "Hello World"); [Pool drain]; return 0;} /*ps:: One thing to note: objective-c2.0 will nsautoreleasepool *pool = [NSAutoreleasePool alloc] init]; and [Pool drain]; Replaced with "@autoreleasepool {}", if you just want to learn objective-c programming in Ubuntu, you can not write nsautoreleasepool, [pool drain], these two lines of code, no error! */
Step three: Compile gcc ' gnustep-config--objc-flags '-lgnustep-base hello.m-o Hello
If the following error occurs during compilation
Gcc:error trying to exec ' cc1obj ': execvp:no such file or directory
Run the following command
sudo apt-get install GOBJC
Run again after compiling
./hello
Executing the program would result in output similar to the following:
2009-09-15 10:48:39.772 prog1[12906] Hello World
Tips:
Every time you compile, you always write a bunch of
GCC ' gnustep-config--objc-flags '-lgnustep-base. m source file-O generated executable file
Here to simplify, write a makefile, the code is as follows:
app:$ (s) gcc ' gnustep-config--objc-flags ' $ (s)-O app-lgnustep-base-lobjc clean:rm *.d rm App
Each execution requires
Make s=.m source file name//run:./app//need make clean before compiling again
This article is from the "happy Programming _ Endless" blog, please be sure to keep this source http://happyliu.blog.51cto.com/501986/1621679
How to learn Objective-c on Linux