1. 程式人生 > >Xcode編譯報錯duplicate symbol _base64Decode in:

Xcode編譯報錯duplicate symbol _base64Decode in:

如題,我的專案中用到了zBarSDK和微信SDK,然後編譯時報錯:

duplicate symbol _base64Decode in:
    /Users/Evan/Documents/work-fight/JdysrFight/fightGame/frameworks/runtime-src/proj.ios_mac/ios/wxSDK/libWeChatSDK.a(base64.o)
    /Users/Evan/Library/Developer/Xcode/DerivedData/fightGame-guhgqdxpcitnbxafrzzllmvwrjto/Build/Products/Debug-iphoneos/libcocos2d iOS.a(base64.o)
duplicate symbol _main in:
    /Users/Evan/Library/Developer/Xcode/DerivedData/fightGame-guhgqdxpcitnbxafrzzllmvwrjto/Build/Intermediates/fightGame.build/Debug-iphoneos/fightGame-mobile.build/Objects-normal/arm64/main.o
    /Users/Evan/Library/Developer/Xcode/DerivedData/fightGame-guhgqdxpcitnbxafrzzllmvwrjto/Build/Products/Debug-iphoneos/libcocos2d iOS.a(flatc.o)
ld: 2 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

原因:

意思就是在這兩個庫中都定義了_base64_encode,編譯器認為你重複定義了。至於為什麼編譯器認為重複定義,個人認為編譯器編譯全域性變數時會根據名字進行編譯,會把相同名稱的全域性變數編譯為相同變數,也就是多個編譯成一個,而編譯器認為這樣可能會引起錯誤,就提醒使用者這裡有錯。

解決方法:

刪掉 TARGETS->Build Settings->other linker flag-> -all_load