重复符号 - 链接器命令失败,退出代码为 1(使用 -v 查看调用)?

Duplicate Symbol - linker command failed with exit code 1 (use -v to see invocation)?

根据教程构建 iOS 应用程序,我收到此消息:

Ld /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Products/Debug-iphonesimulator/FirstGame.app/FirstGame normal i386
    cd /Users/EvanBresnan/Documents/Xcode/FirstGame
    export IPHONEOS_DEPLOYMENT_TARGET=9.2
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk -L/Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Products/Debug-iphonesimulator -F/Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Products/Debug-iphonesimulator -filelist /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Intermediates/FirstGame.build/Debug-iphonesimulator/FirstGame.build/Objects-normal/i386/FirstGame.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.2 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -dependency_info -Xlinker /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Intermediates/FirstGame.build/Debug-iphonesimulator/FirstGame.build/Objects-normal/i386/FirstGame_dependency_info.dat -o /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Products/Debug-iphonesimulator/FirstGame.app/FirstGame

duplicate symbol _HighScoreNumber in:
    /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Intermediates/FirstGame.build/Debug-iphonesimulator/FirstGame.build/Objects-normal/i386/ViewController.o
    /Users/EvanBresnan/Library/Developer/Xcode/DerivedData/FirstGame-ekyyaqwhjsjimddxggwkkkgblylu/Build/Intermediates/FirstGame.build/Debug-iphonesimulator/FirstGame.build/Objects-normal/i386/Game.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

来自错误信息

duplicate symbol _HighScoreNumber in:...

我猜你在两个文件中声明了全局变量 _HighScoreNumber(或者可能在 header 中,在两个文件中导入)。检查 _HighScoreNumber 的声明位置和方式,并将其移动到正确的位置。

我最近遇到了同样的问题。我知道 E。 Brez 得到了答案,但为了帮助其他可能遇到我遇到的同样问题的人。
根据我的申请流程,我正在使用与打印机相关的第三方 class 进行打印。为了使用它,我在我的文件 ImagePrintViewControllerPrintResultViewController 中分别创建了那个 class 的对象,并将所需的数据传递给它。

在我的场景中,我的两个文件 /Library/Developer/Xcode/DerivedData/../x86_64/ImagePrintViewController.o 中的变量名称如 _printerSetup 出现了相同的错误 和 /Library/Developer/Xcode/DerivedData/../x86_64/PrintResultViewController.o
我在我的两个文件中都搜索了上述变量名。但是我没找到。

在搜索了很长时间之后,我想到 删除我的第二个文件的引用,即在我的第一个文件中合并代码后 BRPrintResultViewController.hBRPrintResultViewController.m

有了这个我找到了我的解决方案并且我的代码在这之后运行良好。