注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 linux服务器被黑了
 帮助

Learn Objective-C on Ubuntu


2008-05-05 09:37:42
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://speedooo.blog.51cto.com/226772/74919
Objective-C is used primarily on Mac OSX and GNUStep. If  you want to learn it without Mac,  you can install GNUStep on Ubuntu.

make sure/test GNUStep installed on your Ubuntu(8.04).

add script to your .bashrc file
#set GNUstep
GNUSTEP_ROOT=/usr/share/GNUstep
export GNUSTEP_ROOT
source /usr/share/GNUstep/Makefiles/GNUstep.sh


Try your first Objective-C code,

>mkdir test
create source code called source.m under test dir
#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 that 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

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

create filename GNUmakefile with code like
include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = LogTest
LogTest_OBJC_FILES = source.m

include $(GNUSTEP_MAKEFILES)/tool.make

compile with type  command make

run the program with command ./obj/LogTest

got message:
"This is the string value of the Test class"

本文出自 “我爱我家” 博客,请务必保留此出处http://speedooo.blog.51cto.com/226772/74919





    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: