如何在ubuntu下搭建Objective-C开发环境

sudo apt-get install build-essential gnustep gobjc gnustep-make libgnustep-base-dev gnustep-devel

编辑 .bashrc 加入
1
2
3
4
   
#set GNUstep
GNUSTEP_ROOT=/usr/share/GNUstep
export GNUSTEP_ROOT
source /usr/share/GNUstep/Makefiles/GNUstep.sh

写段小程序测试下:
建个目录 test
1
   
mkdir test

创建文件hello.m,内容如下
   
#include <stdio.h>

/*
* The next #include line is generally present in all Objective-C
* source files that use GNUstep.  The Foundation.h header file
* includes all the other standard header files you need.
*/
#include <Foundation/Foundation.h>

/*
* declare the Test class implements the class method (classStringValue).
*/
@interface Test
+ (const char *) classStringValue;
@end

/**
* Define the Test class and the class method (classStringValue).
*/
@implementation Test
+ (const char *) classStringValue;
{
return “this is the string value of the Test class”;
}
@end

/**
* main() function: pass a message to the Test class and print the returned string
*/
int main(void)
{
printf(“%s/n”, [Test classStringValue]);
return 0;
}

当然还有很重要的GNUmakefile
   
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = LogTest
#LogTest 将会是生成的可执行文件的文件名
LogTest_OBJC_FILES = hello.m
#LogTest_OBJC_FILES 里的 LogTest 必须同上文 LogTest 相同
#hello.m 就是刚编辑的Objective-C源文件
include $(GNUSTEP_MAKEFILES)/tool.make

然后执行 make
如果成功就会出现obj目录
使用 ./obj/LogTest 执行

搞定
希望能对刚入们的iphone开发者有用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值