Ubuntu 下 Objective-C 开发环境

装一堆东西先

1
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,内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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

1
2
3
4
5
6
7
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 执行

搞定

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
This entry was posted in Technologies and tagged , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>