0

我的程序出现错误“链接器命令失败,退出代码为 1(使用 -v 来查看调用)”,我不知道该怎么做。是的,我知道还有其他问题,我阅读了它们并尝试了不同的解决方案,但我认为问题不同。我已经检查了存储在桌面上的项目文件和库/开发人员中的项目文件,但我找不到任何重复的类,即使它告诉了我。

如果您需要,我也可以给您我的代码,但希望我不必这样做。谢谢!:D

完整错误报告:ld /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Products/Debug/ProjAllele normal x86_64 cd /Users/ethen/Desktop/ProjAllele setenv MACOSX_DEPLOYMENT_TARGET 10.8 /Applications/Xcode.app/ Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users /ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Products/Debug -F/Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Products/Debug -filelist /Users/ethen /Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele。build/Objects-normal/x86_64/ProjAllele.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -fobjc-link-runtime -framework Foundation -o /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb /构建/产品/调试/ProjAllele

duplicate symbol _OBJC_METACLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Organism.o
duplicate symbol _OBJC_CLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Organism.o
duplicate symbol _OBJC_METACLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Pea.o
duplicate symbol _OBJC_CLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Pea.o
duplicate symbol _OBJC_METACLASS_$_Plant in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Pea.o
duplicate symbol _OBJC_CLASS_$_Plant in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Pea.o
duplicate symbol _OBJC_METACLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Plant.o
duplicate symbol _OBJC_CLASS_$_Organism in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Plant.o
duplicate symbol _OBJC_METACLASS_$_Plant in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Plant.o
duplicate symbol _OBJC_CLASS_$_Plant in:
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/main.o
    /Users/ethen/Library/Developer/Xcode/DerivedData/ProjAllele-asuihysyexvjvmdsgfladthghavb/Build/Intermediates/ProjAllele.build/Debug/ProjAllele.build/Objects-normal/x86_64/Plant.o
ld: 10 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
4

1 回答 1

0

您在评论中写道:“main.m 进口 Pea.h Pea.h 进口 Plant.m,...”。

有问题。“Pea.h”必须导入“Plant.h”,而不是“Plant.m”。

否则“Plant.m”中的Plant类在所有导入“Pea.h”的源文件中编译,例如在“main.m”中,导致重复定义错误。

于 2013-07-11T22:27:54.830 回答