• 安装GNUstep并运行第一个objc程序


      在windows环境下安装GNUstep,运行objective-c程序,今天试了一下,记录一下操作步骤,
     
    1,登陆http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/网站下载GNUstep的三件套。很多文章都是写的下载两个程序,其实现在GCC在第三个文件里了。仅仅前两个是不行的。
    2,然后按照下面的顺序安装这四个文件到同一个目录(例如:C:GNUstep):
          (1.)gnustep-msys-system-xxx.exe
          (2.)gnustep-core-xxx.exe
          (3.)gnustep-devel-xxx.exe
          (4.)gnustep-cairo-xxx.exe

    3,给个例子吧:例如在F盘目录下用文本编辑一个文件Fraction.m,代码如下(最简单的Obj-C程序):

     

    #import <Foundation/Foundation.h>

    int main(int argc, char *argv[])  {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    NSLog(@"Hello world!");

    [pool drain]; 

    return 0; 

    } 

     

    首先在Shell输入 cd f: 切换到F盘目录,然后

    在Shell中输入命令:gcc -fconstant-string-class=NSConstantString -c Fraction.m -I /GNUstep/System/Library/Headers

    这是目录里就会生成一个Fraction.o文件。(成功完成此步骤不会有任何显示在命令行中,若有显示说明有错误)

    接下来输入命令gcc -o Fraction Fraction.o -L /GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base

    此时成功的话就会在目录里生成一个Fraction.exe文件。

    最后使用命令 ./Fraction.exe会看到输出的结果,我的结果是:2014-12-20 15:30:33.078 Fraction[15344] Hello world!

    成功!

    4,问题解决

    (1),unrecognized option '-class=NSConstantString' 错误,原因是多了空格。

    (2),执行./Fraction.exe的时候,报错,reason:bad sequence length in constant string,是因为Fraction.m文件的保存格式应该为utf-8.

    重要命令:

    go to the path: cd f: cd iOS/codeOfObjc

    create xxxx.o file: gcc -fconstant-string-class=NSConstantString -c hello.m -I/GNUstep/System/Library/Headers

    create xxxx.exe file: gcc -o hello hello.o -L/GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base run the xxxx.exe file: ./helle.exe

  • 相关阅读:
    osg::BlendFunc来设置透明度
    LCA(Tarjan)
    CODEVS1073 家族 (并查集)
    CODEVS1533 互斥的数(哈希表)
    2014-12-4
    BZOJ2661 连连看 (费用流)
    2014-11-30
    JAVA语法基础作业——动手动脑以及课后实验性问题
    课后作业01——相加
    再读大道至简第二章
  • 原文地址:https://www.cnblogs.com/vonk/p/4175339.html
Copyright © 2020-2023  润新知