天天看點

2dx-lua Other Linker Flags 設定成 -ObjC 真機編譯報錯"_GCControllerDidDisconnectNotification"

原文位址:http://www.cocoachina.com/bbs/read.php?tid=225869

用的 cocos2dx-lua quick3.3,Other Linker Flags 設定成 -ObjC 時候, 真機無法編譯通過

報錯如下:

Undefined symbols for architecture armv7s:

  "_GCControllerDidDisconnectNotification", referenced from:

      -[GCControllerConnectionEventHandler observerConnection:disconnection:] in libcocos2dx iOS.a(CCController-iOS.o)

  "_GCControllerDidConnectNotification", referenced from:

      -[GCControllerConnectionEventHandler observerConnection:disconnection:] in libcocos2dx iOS.a(CCController-iOS.o)

  "_OBJC_CLASS_$_GCController", referenced from:

      objc-class-ref in libcocos2dx iOS.a(CCController-iOS.o)

     (maybe you meant: _OBJC_CLASS_$_GCControllerConnectionEventHandler)

ld: symbol(s) not found for architecture armv7s

clang: error: linker command failed with exit code 1 (use -v to see invocation)

我用的是phones 6.1.3系統, 接入天馬廣告SDK,這個sdk要求要将Other Linker Flags 設定成 -ObjC。運作後出現如上錯誤。

--解決方法:

項目->TARGETS->iOS->Build Phases->Link Binary With Libraries

增加庫:

GameController.framework

不行的話就增加兩個庫:

GameController.framework

MediaPlayer.framework

原因參見:http://stackoverflow.com/questions/24844766/linking-errors-when-adding-admob-to-ios-cocos2d-x-3-2

--補充說明:

關于Xcode上的Other linker flags

Targets選項下有Other linker flags的設定,用來填寫XCode的連結器參數,如:-ObjC -all_load -force_load等。

還記得我們在學習C程式的時候,從C代碼到可執行檔案經曆的步驟是:

源代碼 > 預處理器 > 編譯器 > 彙編器 > 機器碼 > 連結器 > 可執行檔案

在最後一步需要把.o檔案和C語言運作庫連結起來,這時候需要用到ld指令。源檔案經過一系列處理以後,會生成對應的.obj檔案,然後一個項目必然會有許多.obj檔案,并且這些檔案之間會有各種各樣的聯系,例如函數調用。連結器做的事就是把這些目标檔案和所用的一些庫連結在一起形成一個完整的可執行檔案。

如果要詳細研究連結器做了什麼,請看:http://www.dutor.net/index.php/2012/02/what-linkers-do/

那麼,Other linker flags設定的值實際上就是ld指令執行時後面所加的參數。

下面逐個介紹3個常用參數:

-ObjC:加了這個參數後,連結器就會把靜态庫中所有的Objective-C類和分類都加載到最後的可執行檔案中

-all_load:會讓連結器把所有找到的目标檔案都加載到可執行檔案中,但是千萬不要随便使用這個參數!假如你使用了不止一個靜态庫檔案,然後又使用了這個參數,那麼你很有可能會遇到ld: duplicate symbol錯誤,因為不同的庫檔案裡面可能會有相同的目标檔案,是以建議在遇到-ObjC失效的情況下使用-force_load參數。

-force_load:所做的事情跟-all_load其實是一樣的,但是-force_load需要指定要進行全部加載的庫檔案的路徑,這樣的話,你就隻是完全加載了一個庫檔案,不影響其餘庫檔案的按需加載

繼續閱讀