11

それで、iPhone 用のエンジンを開発しました。このエンジンを使って、いくつかの異なるゲームを作成したいと思います。エンジンのファイルを各ゲームのプロジェクト ディレクトリ内にコピー アンド ペーストするのではなく、各ゲームからエンジンにリンクする方法を考えました。少し調べてみたところ、iPhone でこれを行うには静的ライブラリが最適な方法のようです。

Skeleton という新しいプロジェクトを作成し、すべてのエンジン ファイルをそこにコピーしました。このガイドを使用して静的ライブラリを作成し、そのライブラリを Chooser というプロジェクトにインポートしました。しかし、プロジェクトをコンパイルしようとすると、ControlScene.mm というファイルに含まれているいくつかの C++ データ構造について、Xcode が不平を言い始めました。ここに私のビルドエラーがあります:

  "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

.framework をリンクしようとしたときに、この問題に遭遇しました。空の cppstub.mmファイルをソースとして(Compile Sourcesフェーズに)追加することで、なんとか修正できました

これを行うと、ある種の C++ コンパイルが強制されているに違いないと思います。理由は聞かないでください。

于 2015-02-24T11:53:30.193 に答える
1

Chooser のビルド設定に入り、"Compile Source As" を検索して Objective-C++ を選択することで問題を解決しました。これはおそらく汚い解決策ですが、うまくいきました。

于 2010-05-17T05:16:43.400 に答える