linux上安装GNUStep

 

1、安装GCC

(1)我安装的是gcc 4.3.1 ,首先安装gmp-4.2.2 mpfr-2.3.1 mpfr带一个patch,这些东东是干什么用的我也不清楚;

(2)因为我的gmpmpfr都是安装在/usr/include下,所以configure时不需要指定--with-mpfr=mpfr目录 --with-gmp=gmp目录。运行configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu --disable-libstdcxx-pch --disable-multilib。使用这个配置成功make之前的一些方案都没有成功,在这里没有指定--enable-languages表明支持所有的语言。

(3)使用gcc main.m可以编译下面的程序了

#import <stdio.h>

int main(int argc, char**argv)
{        
        printf("headfile dir is ok/n");
        return 0;
}

(4)刚高兴一下,编译下面的程序发现很多错误,上网一查,发现原来要使用:

Gcc main.m –l objc

实在是不容易啊。。。

错误:

tmp/ccW8mREn.o: In function `main':

test.m:(.text+0x5e): undefined reference to `objc_get_class'

test.m:(.text+0x71): undefined reference to `objc_msg_lookup'

test.m:(.text+0x98): undefined reference to `objc_msg_lookup'

test.m:(.text+0xc4): undefined reference to `objc_msg_lookup'

test.m:(.text+0xf0): undefined reference to `objc_msg_lookup'

test.m:(.text+0x114): undefined reference to `objc_msg_lookup'

/tmp/ccW8mREn.o: In function `__objc_gnu_init':

test.m:(.text+0x145): undefined reference to `__objc_exec_class'

/tmp/ccW8mREn.o:(.data+0x 1a 8): undefined reference to `__objc_class_name_Object'

collect2: ld returned 1 exit status

 

源代码:

#import <stdio.h>

#import <objc/Object.h>

// ----- @interface section ------

@interface Fraction:Object 

{

int numerator;

int denominator;

}

-(void) Print;

-(void) SetNumerator:(int) n;

-(void) SetDenominator:(int) d;

@end

// @implementation section

@implementation Fraction;

-(void)Print

{

printf("Fraction:%i/%i/n", numerator, denominator);

}

-(void) SetNumerator:(int) n

{

numerator = n;

}

-(void) SetDenominator:(int) d

{

denominator = d;

}

 

@end

 

 

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

{

Fraction* myFraction;

myFraction = [Fraction new];

 

[myFraction SetNumerator:1];

[myFraction SetDenominator:3];

 

[myFraction Print];

[myFraction free];

 

return 0;

}

 

2、安装GNU-Step

这里要推荐一个好网站http://wiki.gnustep.org/index.php/Main_Page

(1)    安装ffcall-1.10

(2)    安装tiff_ 3.8.2

(3)    安装gnustep-make- 2.0.6 并且在.bashrc中加入

GNUSTEP_ROOT=/usr/GNUstep

export GNUSTEP_ROOT

source /usr/GNUstep/System/Library/Makefiles/GNUstep.sh

(4)    重新运行终端,再安装gnustep-base- 1.16.3

(5)    由于/usr/GNUstep目录gcc并不知道,所以编译时要指定:

gcc -I /usr/GNUstep/System/Library/Headers/ -L /usr/GNUstep/System/Library/Libraries/

使用如下命令就可以编译程序下面的程序了。

gcc -fconstant-string-class=NSConstantString -L /usr/GNUstep/System/Library/Libraries/ main.m -lobjc -lgnustep-base

 

#import <Foundation/Foundation.h>

int main(int argc, char**argv)

{

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

 

        NSLog(@"headfile dir is ok/n");

        [pool release];

        return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值