在Xcode中创建Objective-C++静态库

Lan*_*opp 11 iphone xcode objective-c static-libraries objective-c++

所以我开发了一款适用于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
Run Code Online (Sandbox Code Playgroud)

如果有人能够提供一些关于为什么会出现这些问题的见解,我会很感激.

小智 25

将"-lstdc ++"设置为Other Linker Flags


Mic*_*yan 18

问题是您的库是否与libstdc ++动态链接.至于如何修复它,你应该在构建你的库时尝试各种组合中的"-static"," - static-libstdc ++"和"-static-libgcc"(不确定哪些是必需的,但是它们的某些组合应该使它完全静止).

编辑
嗯,事实证明你可以在iPhone上动态链接libstdc ++,所以实际上更好的解决方案就是在你的构建中简单地放入"-lstdc ++"(即明确链接libstdc ++).