zoukankan      html  css  js  c++  java
  • Windows下搭载objectivec环境

    业余出于对IPhone开发的兴趣 先学习下objective c  没Mac 故只能在Windows下折腾了

    1.搭载环境

    http://www.gnustep.org/experience/Windows.html 在这里下载:GNUstep MSYS System,GNUstep Core,GNUstep Devel

    2. 编写helloworld测试
        object-c用的是.m作为默认的后缀,这里是helloworld.m,简单的写下代码:

    #import <Foundation/Foundation.h>
    int main (int argc, const char *argv[]) {
        NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
        NSLog(@"Hello World!");
        [pool drain];
        return 0;
    }

    在Windows环境下用文本编辑器(Editplus,UE等),编写上述代码,并且保存到GNUstep安装目录下的/home下,比如我把GNUstep安装在D:\AppleDevelop\下面,则你的文件应该放在GNUstep\msys\1.0\home\主机名 下面,具体路径可以在console下面运行pwd命令查看,取名为helloworld.m。在GNUstep的console窗口命令行下,

        1、cd /home

        2、gcc -o helloworld helloworld.m -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base

        3、运行helloworld.exe

       说明:第二步中的一些参数明说,如果熟悉Linux/Unix下C/C++编译的话,上述参数应该很熟悉,-I表示头文件查找的路径,-L表示库文件查找路径,-l表示需要链接的库文件。但是,-fconstant-string-class=NSConstantString  对于这个参数可能比较陌生,这个参数主要是指定常量字符串所使用的class。 


    自己写了一个简单的脚本,要是嫌编译源代码麻烦,可以建一个文件,比如lc.sh,然后把下面的内容复制进去:


    #!/bin/sh

    gcc -o $1 $2 -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base

    然后在console下面运行如下命令:chmod +x lc.sh

    以后要编译程序的时候,就在命令行下面输入:./lc.sh helloworld helloworld.m

    文件中的$1和$2分别表示命令行中的helloworld 和 helloworld.m

     helloworld.exe编译并运行成功的话,说明windows下Objective C开发环境就搭建好了,这样就可以开始以廉价方式的学习Objective C。

  • 相关阅读:
    ant-design中日历之自定义头部加上返回今日
    centos7(虚拟机)下安装nginx
    centos7(虚拟机)下安装redis
    log4net
    Autofac
    Utilities
    实体转换类
    CG——Possion Image Editing
    CSC3002学习笔记
    serving 源码
  • 原文地址:https://www.cnblogs.com/zhangqifeng/p/2450864.html
Copyright © 2011-2022 走看看