當編譯AFNetworking 2.0時出現了Undefined symbols for architecture i386

OpenSoucre發表於2013-11-29

當將AFNetworking新增到工程後編譯時出現

Undefined symbols for architecture i386:
  "_SecCertificateCopyData", referenced from:
      _AFCertificateTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecCertificateCreateWithData", referenced from:
      _AFPublicKeyForCertificate in AFSecurityPolicy.o
  "_SecPolicyCreateBasicX509", referenced from:
      _AFPublicKeyForCertificate in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecTrustCopyPublicKey", referenced from:
      _AFPublicKeyForCertificate in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecTrustCreateWithCertificates", referenced from:
      _AFPublicKeyForCertificate in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecTrustEvaluate", referenced from:
      _AFPublicKeyForCertificate in AFSecurityPolicy.o
      _AFServerTrustIsValid in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecTrustGetCertificateAtIndex", referenced from:
      _AFCertificateTrustChainForServerTrust in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
  "_SecTrustGetCertificateCount", referenced from:
      _AFCertificateTrustChainForServerTrust in AFSecurityPolicy.o
      _AFPublicKeyTrustChainForServerTrust in AFSecurityPolicy.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

此時需要匯入3個frameworks

CFNetwork.framework
Security.framework
SystemConfiguration.framework

 我在將AFNetworking 2.0新增到cocos2d的工程專案時,首席必須將與AFNetworking 2.0有關的檔案都變成ARC,具體步驟

 Edit-》Refactor-》Convert to Objective-c ARC...,然後將與AFNetworking 2.0有關的檔案選上,繼續就行

編譯時還可能出現“The current deployment target does not support automated __weak references”,此時需要將__weak變成__unsafe_unretained

還可能在

@property (nonatomic, strong) dispatch_queue_t completionQueue;

出現Property with 'retain(or strong)' attribute must be of object type錯誤,此時將上面變成

@property (nonatomic, assign) dispatch_queue_t completionQueue;

就可以編譯通過

如果感覺麻煩可以試著先建立Application的工程,然後將AFNetwork 2.0新增進去,此時編譯不會報錯,然後再將cocos2d新增進去

按照cocos2d中的AppDelegate修改一下AppDelegate的內容即可,此方法有待嘗試

相關文章