在 Xcode 中使用 C++ 命令行工具时,我的可执行文件突然损坏,构建失败,并且收到 Apple Mach-O 链接器错误。经过大量调试尝试后,我将问题缩小到这部分代码:
struct Word {
std::string word;
int syllCount, phoCount;
std::vector<std::string> syllable, phoneme;
};
struct Unit {
std::string str;
std::vector<int> probs;
};
// **COMMENT OR RECEIVE ERROR HERE**
// std::vector<Word> words;
// std::vector<Unit> units;
只需从头文件中删除两个向量声明,所有错误都会消失;但是,我需要那些向量...
我已经阅读了这个特定的错误,但我发现没有任何东西是由这种方式引起的。我是否犯了一个业余错误,或者这是一个不寻常的错误。无论哪种方式,任何建议都将不胜感激。
顺便说一下,这是错误消息:
duplicate symbol _words in:
>/Users/DASmithII/Library/Developer/Xcode/DerivedData/Organizer->dviebpebgpvwotbsxuwyhrvulzfi/Build/Intermediates/Organizer.build/Debug/Organizer.build/Object>s-normal/x86_64/main.o
>/Users/DASmithII/Library/Developer/Xcode/DerivedData/Organizer->dviebpebgpvwotbsxuwyhrvulzfi/Build/Intermediates/Organizer.build/Debug/Organizer.build/Object>s-normal/x86_64/Global.o
>duplicate symbol _units in:
>/Users/DASmithII/Library/Developer/Xcode/DerivedData/Organizer->dviebpebgpvwotbsxuwyhrvulzfi/Build/Intermediates/Organizer.build/Debug/Organizer.build/Object>s-normal/x86_64/main.o
>/Users/DASmithII/Library/Developer/Xcode/DerivedData/Organizer->dviebpebgpvwotbsxuwyhrvulzfi/Build/Intermediates/Organizer.build/Debug/Organizer.build/Object>s-normal/x86_64/Global.o
>ld: 2 duplicate symbols for architecture x86_64
>clang: error: linker command failed with exit code 1 (use -v to see invocation)