• Windows下安装Object C开发环境,及Hello Word(转)


    Windows下安装Object C开发环境,及Hello Word

    最近想学习iphone开发,但是由于没有c基础,只有java基础。所以先从基础学习,首先是搭建环境,目前手头没有mac机子,只能先在windows下学习基本语法。还好找到了GNUset,可以利用GNUstep在windows下模拟object c开发环境。

    官方网址:http://www.gnustep.org/

    安装:

    GNUstep Windows Installer提供了Windows平台下的Objective-C的模拟开发环境,一共有四个软件包,其中GNUstep SystemGNUstep Core是必装的,GNUstep DevelCairo Backend是选装的。甭管必装选装,一次性全安上,免得以后麻烦。

    编写HelloWord

    几乎所有的开发环境都是以HelloWord开始,在这里我们先编写HelloWord.

    安装完成后,在开始菜单里的GNUstep选项里执行shell,就能打开命令行,在这里就可以使用vi编写Object-C程序了,不过操作起来总有些繁琐,其实也可以直接在Windows里进入C:GNUstephomeusername目录,在这里用你喜欢的工具编写Object-C程序,然后再进入shell里编译。 
    直接给出helloworld.m文件内容,取自Programming in Objective-C 2.0一书:

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

    第一次编译:

    gcc -o helloworld helloworld.m

    结果出现错误信息,找不到头文件:

    helloworld.m:1:34: Foundation/Foundation.h: No such file or directory 
    helloworld.m: In function `main’: 
    helloworld.m:4: error: `NSAutoreleasePool’ undeclared (first use in this function) 
    helloworld.m:4: error: (Each undeclared identifier is reported only once 
    helloworld.m:4: error: for each function it appears in.) 
    helloworld.m:4: error: `pool’ undeclared (first use in this function) 
    helloworld.m:5: error: cannot find interface declaration for `NXConstantString’

    image 
    第二次编译:

    gcc -o helloworld helloworld.m  
    -I /GNUstep/System/Library/Headers/

    结果出现错误信息,找不到接口声明:

    helloworld.m: In function `main’: 
    helloworld.m:5: error: cannot find interface declaration for `NXConstantString’

    第三次编译:

    gcc -o helloworld helloworld.m  
    -fconstant-string-class=NSConstantString  
    -I /GNUstep/System/Library/Headers/

    结果出现错误信息,找不到链接库:

    helloworld.m:(.text+0×33): undefined reference to `_objc_get_class’ 
    helloworld.m:(.text+0×45): undefined reference to `_objc_msg_lookup’ 
    helloworld.m:(.text+0×64): undefined reference to `_objc_msg_lookup’ 
    helloworld.m:(.text+0×80): undefined reference to `_NSLog’ 
    helloworld.m:(.text+0×93): undefined reference to `_objc_msg_lookup’ 
    helloworld.m:(.text+0xbc): undefined reference to `___objc_exec_class’ 
    helloworld.m:(.data+0×74): undefined reference to `___objc_class_name_NSAutoreleasePool’ 
    helloworld.m:(.data+0×78): undefined reference to `___objc_class_name_NSConstantString’ 
    collect2: ld returned 1 exit status

    第四次编译:

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

     执行上面的路径还是会提示找不到Foundation/Foundation.h 需要加上绝对路径,命令

    gcc -o helloworld helloworld.m -fconstant-string-class=NSConstantString -I C:GNUstepGNUstepSystemLibraryHeaders -L C:GNUstepGNUstepSystemLibraryLibraries -lobjc -lgnustep-base

    注意:helloworld.m必须出现在-lobjc和-lgnustep-base的前面,否则会出错。 
    此时会出现一些info提示信息,不过不碍事,终于成功了生成了可执行文件,执行看结果。

    ./helloworld.exe     windows命令行:helloworld

    结果是:

    image

    注意,可以利用粘贴复制命令:Ctrl+p

  • 相关阅读:
    Spring Boot学习(三)解析 Spring Boot 项目
    Spring Boot学习(二)搭建一个简易的Spring Boot工程
    Spring Boot学习(一)初识Spring Boot
    Spring学习(十)Spring知识点汇总
    Oracle学习(十六)Oracle安装
    Spring学习(九)Spring 和数据库编程【了解】
    Spring学习(八)AOP详解
    Spring学习(七)bean装配详解之 【通过注解装配 Bean】【自动装配的歧义解决】
    Spring学习(六)bean装配详解之 【通过注解装配 Bean】【基础配置方式】
    Spring学习(五)bean装配详解之 【XML方式配置】
  • 原文地址:https://www.cnblogs.com/antyi/p/3271956.html
Copyright © 2020-2023  润新知