How to learn Objective-c on Linux

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.