首页 文章

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

提问于
浏览
-1

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

  • 1

    来自错误消息

    duplicate symbol _HighScoreNumber in:...
    

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

  • 0

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

    在我的场景中,我在我的两个文件 /Library/Developer/Xcode/DerivedData/../x86_64/ImagePrintViewController.o/Library/Developer/Xcode/DerivedData/../x86_64/PrintResultViewController.o 中得到了与变量名称相同的错误,如 _printerSetup .
    我在我的两个文件中都搜索了上面的变量名 . 但我找不到 .

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

    有了这个,我找到了我的解决方案,我的代码运行良好 .

相关问题