objective c ubuntu gcc hello world

Posted by bower on November 14, 2010
linux/ubuntu

分享给你的朋友->bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

gcc 是可以写objective c的,所以可以在ubuntu 编写

首先要用编译器

sudo apt-get install gobjc

然后写hello.m
vim hello.m


// hello.m
#import
#import

@interface Number: Object
{
@public
int number;

}
- (void)printNum;

@end

@implementation Number: Object

- (void)printNum
{
printf("%d\n", number);
}

@end

int main(void)
{
Number *myNumber = [Number new]; // equal to [[Number alloc] init]
myNumber->number = 6;
[myNumber printNum];
return 0;
}

编译

gcc -o hello hello.m -Wall -lobjc
运行
./hello

分享到:人人网开心网腾讯微博新浪微博豆瓣分享腾讯空间百度搜藏腾讯书签

分享给你的朋友->bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word