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

时间:2016-02-05 22:40:39

标签: ios objective-c linker-errors duplicate-symbol

根据教程构建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)

2 个答案:

答案 0 :(得分:1)

来自错误消息

duplicate symbol _HighScoreNumber in:...

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

答案 1 :(得分:0)

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

在我的方案中,我在我的两个文件_printerSetup中使用/Library/Developer/Xcode/DerivedData/../x86_64/ImagePrintViewController.o等变量名称收到相同的错误 和/Library/Developer/Xcode/DerivedData/../x86_64/PrintResultViewController.o
我在我的两个文件中都搜索了上面的变量名。但我找不到。

经过长时间搜索后,我在第一个文件中合并代码后,得到了第二个文件删除参考的想法,即BRPrintResultViewController.hBRPrintResultViewController.m

有了这个,我发现了我的解决方案,之后我的代码运行良好。