为了账号安全,请及时绑定邮箱和手机立即绑定

Objective-C composite object 合成对象问题

Objective-C composite object 合成对象问题

噜噜哒 2019-04-19 16:12:42
最近看《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)求熟手帮忙看下哪里出问题了
查看完整描述

2 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

解决了,把composite的那个.m文件里的@interface拆分出.h
main.m里再引入这个.h就可以成功build了。
但是类的分类文件只用.m不分出.h是可以build的
                            
查看完整回答
反对 回复 2019-04-19
?
侃侃无极

TA贡献2051条经验 获得超10个赞

error:linkercommandfailedwithexitcode1(use-vtoseeinvocation)
这个错误信息的意思就是link出错了,如果你不详细的出错信息贴出来的话,那么它并没有什么卵用。
                            
查看完整回答
反对 回复 2019-04-19
  • 2 回答
  • 0 关注
  • 409 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信