问题描述
我没有用于iOS开发的Mac机.现在我处于学习阶段,想开始在Linux上进行ios开发.那么有可能在Linux环境上运行Objective-C代码吗?
I don't have the Mac machine for ios development. Now I am in a learning stage and want to start the ios development on Linux. So is it possible to run the Objective-C Code on Linux environment?
推荐答案
是的,在Ubuntu中可以通过以下方式运行Objective-C代码:
Yes it is possible in Ubuntu to Run the Objective-C code in the following way:
在Ubuntu中,使用以下命令安装GNU Objective-C编译器和Gnu-step开发库:
In Ubuntu, Install GNU Objective-C Compiler and the Gnu-step Development Libraries with the following command::
sudo apt-get –y install gobjc gnustep gnustep-devel
现在键入下面给出的程序,并以.m扩展名保存文件.
Now type the Program given below and save the file with .m extension.
例如,hello.m
// 'Hello World' Program in Objective-C
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return 0;
}
现在使用以下命令编译程序:
Now Compile the Program with the following command:
gcc $(gnustep-config --objc-flags) -o hello hello.m $(gnustep-config --base-libs)
或者您可以编写此示例Makefile:
Or you could write this sample Makefile:
CC := gcc
GNUSTEP_LIBS = $(shell gnustep-config --base-libs)
GNUSTEP_FLAGS = $(shell gnustep-config --objc-flags)
.PHONY = clean all
PROGS = hello class_hello
all: $(PROGS)
%.o: %.m
$(CC) $(GNUSTEP_FLAGS) -c $^
hello: hello.o
$(CC) -o $@ $^ $(GNUSTEP_LIBS)
clean:
rm $(PROGS) *.o
然后运行:
make
现在使用以下命令运行可执行文件:
Now Run the executable with the following command:
./hello
输出-> 2014-11-14 15:47:32.628 hello[2786] Hello, World!
输出的格式是这样的-
<DATE> <TIME> <NAME OF THE EXECUTABLE[NUMBER]> <ACTUAL OUTPUT>
这篇关于Ubuntu-Linux的Objective-C环境设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!