不解释 语句了,以下列出了两种情况
1 执行 单个 文件 ,如源码:(helloworld.m)
#import <Foundation/Foundation.h>
int main(int argc , const char *argv[]){
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"programming is fun!");
[pool drain];
return 0;
}
建立 make.sh文件,内容 :
#!/bin/sh
gcc -o $1 $2 -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base
使用时:sh make.sh helloworld helloworld.m 即可编译成功
2 执行多个文件 Fraction.h ,Fraction.m ,main.m(源码就不贴了,因为这个帖子主要是建立 shell脚本)
A 首先 把main.m生成main.o,sh文件内容:
#!/bin/sh
gcc -fconstant-string-class=NSConstantString -c $1 -I /GNUstep/System/Library/Headers
使用时:sh sh main.m即可生成 main.o文件
B 其次 把Fraction.m生成Fraction.o,sh文件内容:
#!/bin/sh
gcc -c $1 -I /GNUstep/System/Library/Headers
使用时:sh sh Fraction.m即可生成 Fraction.o文件
C 最后生成main.exe文件,sh文件内容:
#!/bin/sh
gcc -o $1 $2 Fraction.o -L /GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base
使用时:sh sh main main.o即可生成 main.exe文件
在执行 多个文件时有些麻烦,但是暂时没有更好的办法来解决,期待有朋友有更好的办法提供出来。