Learn Objective-C on Ubuntu

以你之姓@ 2022-01-17 06:15 206阅读 0赞

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

转载于:https://blog.51cto.com/his9932/605374

发表评论

表情:
评论列表 (有 0 条评论,206人围观)

还没有评论,来说两句吧...

相关阅读