最近看《Objective-C程序设计》,11章有个合成对象自己写了一个例子Xcode没报错,编译时报错了//"Rectangle.h"@interfaceRectangle:NSObject@propertyintwidth,height;-(void)setWidth:(int)wandHeight:(int)h;-(int)area;@end#import"Rectangle.h"@interfaceSquare_c:NSObject{Rectangle*rect;}-(instancetype)init;-(instancetype)initWithSide:(int)s;-(void)setSide:(int)s;-(int)side;-(int)area;@end@implementationSquare_c-(instancetype)init{self=[superinit];if(self){rect=[[Rectanglealloc]init];}return[selfinitWithSide:0];}-(instancetype)initWithSide:(int)s{self=[superinit];if(self)[rectsetWidth:sandHeight:s];returnself;}-(void)setSide:(int)s{[rectsetWidth:sandHeight:s];}-(int)side{returnrect.width;}-(int)area{return[rectarea];}@endintmain(intargc,char*argv[]){@autoreleasepool{Square_c*square_c=[[Square_calloc]initWithSide:20];}}Xcode编译后报错Ld/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Products/Debug/prog1normalx86_64cd/Project/prog1exportMACOSX_DEPLOYMENT_TARGET=10.10/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-archx86_64-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk-L/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Products/Debug-F/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Products/Debug-filelist/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/prog1.LinkFileList-mmacosx-version-min=10.10-fobjc-arc-fobjc-link-runtime-Xlinker-dependency_info-Xlinker/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/prog1_dependency_info.dat-o/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Products/Debug/prog1duplicatesymbol_OBJC_IVAR_$_Square2.rectin:/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/main.o/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/Square_composite.oduplicatesymbol_OBJC_CLASS_$_Square2in:/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/main.o/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/Square_composite.oduplicatesymbol_OBJC_METACLASS_$_Square2in:/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/main.o/Users/ma/Library/Developer/Xcode/DerivedData/prog1-eexmdvqxkooeorhbkjzcupkepwqy/Build/Intermediates/prog1.build/Debug/prog1.build/Objects-normal/x86_64/Square_composite.old:3duplicatesymbolsforarchitecturex86_64clang:error:linkercommandfailedwithexitcode1(use-vtoseeinvocation)求熟手帮忙看下哪里出问题了
添加回答
举报
0/150
提交
取消