Learn Objective-C on Ubuntu
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
/*
* 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
/*
* 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
转载于//blog.51cto.com/his9932/605374
还没有评论,来说两句吧...