簡體   English   中英

在Xcode中創建Objective-C ++靜態庫

[英]Creating an Objective-C++ Static Library in Xcode

所以我開發了一款適用於iPhone的引擎,我想用它制作幾款不同的游戲。 我沒有在每個游戲的項目目錄中復制和粘貼引擎文件,而是從每個游戲鏈接到引擎,所以如果我需要對其進行更改,我只需要這樣做一次。 在稍微調整一下之后,似乎靜態庫是在iPhone上執行此操作的最佳方式。

我創建了一個名為Skeleton的新項目,並將所有引擎文件復制到它上面。 我使用指南創建了一個靜態庫,並將該庫導入了一個名為Chooser的項目中。 但是,當我嘗試編譯項目時,Xcode開始抱怨我在一個名為ControlScene.mm的文件中包含的一些C ++數據結構。 這是我的構建錯誤:

  "operator delete(void*)", referenced from:


      -[ControlScene dealloc] in libSkeleton.a(ControlScene.o)


      -[ControlScene init] in libSkeleton.a(ControlScene.o)


      __gnu_cxx::new_allocator<operation_t>::deallocate(operation_t*, unsigned long)in libSkeleton.a(ControlScene.o)


      __gnu_cxx::new_allocator<operation_t*>::deallocate(operation_t**, unsigned long)in libSkeleton.a(ControlScene.o)


  "operator new(unsigned long)", referenced from:


      -[ControlScene init] in libSkeleton.a(ControlScene.o)


      __gnu_cxx::new_allocator<operation_t*>::allocate(unsigned long, void const*)in libSkeleton.a(ControlScene.o)


      __gnu_cxx::new_allocator<operation_t>::allocate(unsigned long, void const*)in libSkeleton.a(ControlScene.o)


  "std::__throw_bad_alloc()", referenced from:


      __gnu_cxx::new_allocator<operation_t*>::allocate(unsigned long, void const*)in libSkeleton.a(ControlScene.o)


      __gnu_cxx::new_allocator<operation_t>::allocate(unsigned long, void const*)in libSkeleton.a(ControlScene.o)


  "___cxa_rethrow", referenced from:


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_create_nodes(operation_t**, operation_t**)in libSkeleton.a(ControlScene.o)


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_initialize_map(unsigned long)in libSkeleton.a(ControlScene.o)


  "___cxa_end_catch", referenced from:


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_create_nodes(operation_t**, operation_t**)in libSkeleton.a(ControlScene.o)


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_initialize_map(unsigned long)in libSkeleton.a(ControlScene.o)


  "___gxx_personality_v0", referenced from:


      ___gxx_personality_v0$non_lazy_ptr in libSkeleton.a(ControlScene.o)


      ___gxx_personality_v0$non_lazy_ptr in libSkeleton.a(MenuLayer.o)


  "___cxa_begin_catch", referenced from:


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_create_nodes(operation_t**, operation_t**)in libSkeleton.a(ControlScene.o)


      std::_Deque_base<operation_t, std::allocator<operation_t> >::_M_initialize_map(unsigned long)in libSkeleton.a(ControlScene.o)


ld: symbol(s) not found


collect2: ld returned 1 exit status

如果有人能夠提供一些關於為什么會出現這些問題的見解,我會很感激。

將“-lstdc ++”設置為Other Linker Flags

問題是您的庫是否與libstdc ++動態鏈接。 至於如何修復它,你應該在構建你的庫時嘗試各種組合的“-static”,“ - static-libstdc ++”和“-static-libgcc”(不確定哪些是必需的,但是它們的一些組合應該使它完全靜止)。

編輯
好吧,事實證明你可以在iPhone上動態鏈接libstdc ++,所以實際上更好的解決方案是在你的構建中簡單地放入“-lstdc ++”(即顯式鏈接libstdc ++)。

我通過進入Chooser的構建設置,搜索“Compile Source As”並選擇Objective-C ++來解決問題。 這可能是一個骯臟的解決方案,但它確實有效。

我試圖鏈接.framework時遇到了這個問題。 我設法通過添加一個空的 cppstub.mm文件作為源來修復它(到Compile Sources階段)

我想當你這樣做時必須強制進行某種C ++編譯,不要問我原因

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM