11

所以我为 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

如果有人可以就为什么会出现这些问题提供一些见解,我将不胜感激。

4

4 回答 4

25

将“-lstdc++”设置为其他链接器标志

于 2012-04-20T07:20:26.973 回答
18

问题是您的库正在动态链接 libstdc++。至于如何修复它,您应该在构建库时尝试各种组合的“-static”、“-static-libstdc++”和“-static-libgcc”(不确定需要哪些,但应该使用它们的某种组合)使其完全静止)。

编辑
好吧,事实证明,您可以在 iPhone 上动态链接 libstdc++,因此实际上更好的解决方案是在构建中简单地放入“-lstdc++”(即显式链接到 libstdc++)。

于 2010-05-17T05:04:08.267 回答
1

我通过进入选择器的构建设置、搜索“编译源为”并选择 Objective-C++ 来解决问题。这可能是一个肮脏的解决方案,但它有效。

于 2010-05-17T05:16:43.400 回答
1

我在尝试链接 .framework 时遇到了这个问题。我已经设法通过添加一个 cppstub.mm文件作为源(到Compile Sources阶段)来修复它

我想当你这样做时它一定是强制进行某种 C++ 编译,不要问我为什么

于 2015-02-24T11:53:30.193 回答