Xcode 错误“重复符号”导致 Apple Mach-O 链接器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14256074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode error "Duplicate Symbol" causing Apple Mach-O Linker Error
提问by JamesLCQ
duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToMeViewController.o
duplicate symbol _showGLobalCompany in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
ld: 3 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting the error above in xcode only when I try to build in simulator (on any iOS device I can build without error). I have three classes:
仅当我尝试在模拟器中构建时(在我可以构建而没有错误的任何 iOS 设备上),我才在 xcode 中收到上述错误。我有三个班级:
1.LTGlobalResultsViewController 2.LTJumpToMeViewController 3.LTJumpToPositionViewController
1.LTGlobalResultsViewController 2.LTJumpToMeViewController 3.LTJumpToPositionViewController
All three were created in xcode but both 2 & 3 have been modified outside of xcode and then rebuilt.
这三个都是在 xcode 中创建的,但 2 和 3 都在 xcode 之外进行了修改,然后重新构建。
The @property bool leagueTableLoaded is defined in the header for all three. it is declared as:
@property bool LeagueTableLoaded 在所有三个的标题中定义。它被声明为:
@property bool leagueTableLoaded;
What is it exactly that is causing this error? I have tried the following:
究竟是什么导致了这个错误?我尝试了以下方法:
I have tried renaming leagueTableLoaded in different classes but this doesn't fix it.
I have tried deleting my Derived Data files manually in library/developer/xcode folder.
According to other questions I have checked if I am importing a .m file. This is not the case. Apple Mach-O Linker error ("duplicate symbol")
我曾尝试在不同的类中重命名 LeagueTableLoaded 但这并不能解决它。
我尝试在 library/developer/xcode 文件夹中手动删除我的派生数据文件。
根据其他问题,我检查过我是否正在导入 .m 文件。不是这种情况。Apple Mach-O 链接器错误(“重复符号”)
Any other suggestions or advice? Thanks, James
任何其他建议或建议?谢谢,詹姆斯
ADDITION: As requested please find all the extracts from my .h and .m files that reference leagueTableLoaded or any of the variants I created when trying to get round this error:
附加:根据要求,请从我的 .h 和 .m 文件中找到所有引用 LeagueTableLoaded 或我在尝试解决此错误时创建的任何变体的摘录:
LTJumpToMeViewController.h
@property bool leagueTableLoadedMe;
LTJumpToMeViewController.m
@implementation LTJumpToMeViewController
bool leagueTableLoaded = false;
LTGlobalResultsViewController.h
@property bool globalLeagueTableLoaded;
LTGlobalResultsViewController.m
@implementation LTGlobalResultsViewController
bool leagueTableLoaded = false;
LTJumpToPositionViewController.h
@property bool leagueTableLoadedPos;
LTJumpToPositionViewController.m
@implementation LTJumpToPositionViewController
bool leagueTableLoaded = false;
I can provide more information if required!
如果需要,我可以提供更多信息!
采纳答案by JamesLCQ
In this end this was being caused by the leagueTableLoaded bool being defined in both LTGlobalResultsViewController.m and LTJumpToPositionViewController.m.
最后,这是由 LTGlobalResultsViewController.m 和 LTJumpToPositionViewController.m 中定义的 LeagueTableLoaded bool 引起的。
Removing it from one of them fixed the issue. Although I'm not sure why it was there in the first place! Hope this helps anyone else who experiences the same issue! James
从其中一个中删除它解决了这个问题。虽然我不知道为什么它首先出现在那里!希望这可以帮助遇到相同问题的其他人!詹姆士
回答by rounak
For me a duplicate symbol error came up when I absent mindedly included a .m file instead of a .h (Why does Xcode's autosuggest even show me .m files?!)
对我来说,当我心不在焉地包含 .m 文件而不是 .h 时出现重复符号错误(为什么 Xcode 的自动建议甚至显示 .m 文件?!)
回答by Vineeth Joseph
Xcode error “Duplicate Symbol” causing Apple Mach-O Linker Error is caused by duplicate symbols in Project. Steps to avoid error
Xcode 错误“重复符号”导致 Apple Mach-O 链接器错误是由项目中的重复符号引起的。避免错误的步骤
- Go to project-> Target->Build Phases->Compile sources
- Check for the duplicate file (implementation file)
- Delete the file and add it again
- Clean and run project again
- 转到项目-> 目标->构建阶段->编译源
- 检查重复文件(实现文件)
- 删除文件并重新添加
- 再次清理并运行项目
This worked for me. Hope it helps
这对我有用。希望能帮助到你
回答by Rahul Panzade
In second view controller, you mistakenly #import "First.m", check it must be first.hfile so replaces this with first.h. It's working for me.
在第二个视图控制器中,您错误地#import "First.m",检查它必须是first.h文件,因此将其替换为first.h。它对我有用。