0
我試圖從http://www.otierney.net/objective-c.html編譯下面的例子。它由三個文件:在Linux上編譯目標c
Fraction.h
#import <Foundation/NSObject.h>
@interface Fraction: NSObject {
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator;
-(void) setDenominator;
-(int) numerator;
-(int) denominator;
@end
Fraction.m
#import <stdio.h>
@implementation Fraction
-(void) print {
printf("%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n {
numerator = n;
}
-(void) setDenominator: (int) d {
denominator = d;
}
-(int) denominator {
return denominator;
}
-(int) numerator {
return numerator;
}
@end
的main.m
#import <stdio.h>
#import "Fraction.h"
int
main(int argc, char **argv)
{
//Create a new instance
Fraction *frac = [[Fraction alloc] init];
//set the values
[frac setNumerator: 1];
[frac setDenominator: 3];
//print it
printf("The fraction is: ");
[frac print];
printf("\n");
//Frac memory
[frac release];
return 0;
}
使用下列編譯
$ gcc `gnustep-config --objc-flags` -lobjc -lgnustep-base main.m -o main
這將產生一個main.d文件,這只是ASCII
$ cat main.d
main: main.m Fraction.h /usr/include/GNUstep/Foundation/NSObject.h \
/usr/include/GNUstep/Foundation/NSObjCRuntime.h \
/usr/include/GNUstep/GNUstepBase/GSVersionMacros.h \
/usr/include/GNUstep/GNUstepBase/GSConfig.h \
/usr/include/GNUstep/GNUstepBase/preface.h \
/usr/include/GNUstep/GNUstepBase/GSObjCRuntime.h \
/usr/include/GNUstep/ObjectiveC2/runtime.h \
/usr/include/GNUstep/ObjectiveC2/Availability.h \
/usr/include/GNUstep/Foundation/NSZone.h \
/usr/include/GNUstep/GNUstepBase/GNUstep.h \
/usr/include/GNUstep/Foundation/NSDate.h \
/usr/include/GNUstep/GNUstepBase/NSObject+GNUstepBase.h
Fraction.h:
/usr/include/GNUstep/Foundation/NSObject.h:
/usr/include/GNUstep/Foundation/NSObjCRuntime.h:
/usr/include/GNUstep/GNUstepBase/GSVersionMacros.h:
/usr/include/GNUstep/GNUstepBase/GSConfig.h:
/usr/include/GNUstep/GNUstepBase/preface.h:
/usr/include/GNUstep/GNUstepBase/GSObjCRuntime.h:
/usr/include/GNUstep/ObjectiveC2/runtime.h:
/usr/include/GNUstep/ObjectiveC2/Availability.h:
/usr/include/GNUstep/Foundation/NSZone.h:
/usr/include/GNUstep/GNUstepBase/GNUstep.h:
/usr/include/GNUstep/Foundation/NSDate.h:
/usr/include/GNUstep/GNUstepBase/NSObject+GNUstepBase.h:
請重新格式化。點擊大橙色有說明嗎?就在編輯窗口的上方。 – Jonathan 2010-10-15 18:21:09
問題是什麼? – mathk 2011-05-03 07:30:51