2

こんにちはStackOverflowコミュニティ、

C++静的アーカイブライブラリ用のRubyCAPIラッパーを生成するSWIGプロジェクトがあります。64ビットLinux(FedoraおよびDebianでテスト済み)でコードを生成およびコンパイルするのに問題はありません。残念ながら、アーカイブのOSXバージョンは32ビットのみです。Ruby C Native Extensionとして使用される共有オブジェクトを生成、コンパイル、およびリンクするために、OSX上に32ビットバージョンのRubyを構築しました。

$ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-darwin11]

すべてのオブジェクトは-m32フラグを使用してコンパイルされます。

$ g++ -m32 -Wall -g -c -fPIC -rdynamic ../src/CPPExampleWrapper.cpp ../src/CPPExampleException.cpp ../src/CPPExampleObject.cpp ../src/CPPExampleCallbackFunctor.cpp -I../include/ -I../lib/include/

それに応じてリンクされます:

g++ -m32 -shared -fPIC -o ../lib/cppexample.so ./bin/CPPExampleWrapper.o ../qa_cpp_utils/bin/CPPExampleObject.o ../qa_cpp_utils/bin/CPPExampleCallbackFunctor.o ../qa_cpp_utils/lib/libcppexamplearchive.a -framework CoreFoundation -lpthread

リンク時に、CPPExampleWrapper.oで参照されているシンボルがアーキテクチャi386に対して未定義であることを示すエラーが表示されます。

Undefined symbols for architecture i386:
  "_rb_big2long", referenced from:
      SWIG_AUX_NUM2LONG(unsigned long*)in CPPExampleWrapper.o
  "_rb_big2ulong", referenced from:
      SWIG_AUX_NUM2ULONG(unsigned long*)in CPPExampleWrapper.o
  "_rb_cFalseClass", referenced from:
      _rb_class_of in CPPExampleWrapper.o
  "_rb_cFixnum", referenced from:
      _rb_class_of in CPPExampleWrapper.o
  "_rb_cNilClass", referenced from:
      _rb_class_of in CPPExampleWrapper.o
  "_rb_cObject", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
      _SWIG_Ruby_SetModule in CPPExampleWrapper.o
      _SWIG_Ruby_define_class in CPPExampleWrapper.o
  "_rb_cSymbol", referenced from:
      _rb_class_of in CPPExampleWrapper.o
  "_rb_cTrueClass", referenced from:
      _rb_class_of in CPPExampleWrapper.o
  "_rb_check_type", referenced from:
      _SWIG_Ruby_GetModule in CPPExampleWrapper.o
      _SWIG_Ruby_ConvertPtrAndOwn in CPPExampleWrapper.o
  "_rb_const_get", referenced from:
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
  "_rb_data_object_alloc", referenced from:
      _SWIG_Ruby_SetModule in CPPExampleWrapper.o
      _SWIG_Ruby_NewClassInstance in CPPExampleWrapper.o
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
  "_rb_define_alloc_func", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_define_class", referenced from:
      getNullReferenceError()      in CPPExampleWrapper.o
      getObjectPreviouslyDeletedError()      in CPPExampleWrapper.o
      _SWIG_Ruby_SetModule in CPPExampleWrapper.o
  "_rb_define_class_under", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
      _SWIG_Ruby_define_class in CPPExampleWrapper.o
  "_rb_define_const", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_define_method", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_define_module", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
      _SWIG_Ruby_InitRuntime in CPPExampleWrapper.o
  "_rb_define_module_function", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_define_readonly_variable", referenced from:
      _SWIG_Ruby_SetModule in CPPExampleWrapper.o
  "_rb_define_singleton_method", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_eArgError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
      _wrap_new_JobOrder(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_src_location_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_src_location_get(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_dst_location_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_dst_location_get(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_xfer_params_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      ...
  "_rb_eFatal", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eIOError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eIndexError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eNoMemError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eRangeError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eRuntimeError", referenced from:
      getNullReferenceError()      in CPPExampleWrapper.o
      getObjectPreviouslyDeletedError()      in CPPExampleWrapper.o
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eSyntaxError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eTypeError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_eZeroDivError", referenced from:
      SWIG_Ruby_ErrorType(int)   in CPPExampleWrapper.o
  "_rb_funcall", referenced from:
      _SWIG_RubyRemoveTracking in CPPExampleWrapper.o
  "_rb_gv_get", referenced from:
      _SWIG_Ruby_GetModule in CPPExampleWrapper.o
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
  "_rb_gv_set", referenced from:
      _SWIG_Ruby_GetModule in CPPExampleWrapper.o
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
  "_rb_hash_aref", referenced from:
      _SWIG_RubyInstanceFor in CPPExampleWrapper.o
  "_rb_hash_aset", referenced from:
      _SWIG_RubyAddTracking in CPPExampleWrapper.o
  "_rb_hash_new", referenced from:
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
  "_rb_inspect", referenced from:
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_int2big", referenced from:
      _SWIG_RubyPtrToReference in CPPExampleWrapper.o
      _SWIG_RubyObjectToReference in CPPExampleWrapper.o
      SWIG_From_int(int)   in CPPExampleWrapper.o
  "_rb_intern", referenced from:
      _SWIG_Ruby_InitRuntime in CPPExampleWrapper.o
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
  "_rb_iv_get", referenced from:
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
      _SWIG_Ruby_MangleStr in CPPExampleWrapper.o
  "_rb_iv_set", referenced from:
      _SWIG_Ruby_NewClassInstance in CPPExampleWrapper.o
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
  "_rb_ivar_get", referenced from:
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
  "_rb_ivar_set", referenced from:
      _SWIG_RubyInitializeTrackings in CPPExampleWrapper.o
  "_rb_num2long", referenced from:
      _SWIG_RubyReferenceToObject in CPPExampleWrapper.o
      SWIG_AUX_NUM2LONG(unsigned long*)in CPPExampleWrapper.o
  "_rb_num2ulong", referenced from:
      SWIG_AUX_NUM2ULONG(unsigned long*)in CPPExampleWrapper.o
  "_rb_obj_classname", referenced from:
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_obj_is_kind_of", referenced from:
      _SWIG_Ruby_ConvertPtrAndOwn in CPPExampleWrapper.o
  "_rb_raise", referenced from:
      _wrap_new_JobOrder(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_src_location_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_src_location_get(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_dst_location_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_dst_location_get(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_xfer_params_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_JobOrder_xfer_params_get(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      ...
  "_rb_rescue", referenced from:
      SWIG_AsVal_unsigned_SS_long(unsigned long, unsigned long*)in CPPExampleWrapper.o
      SWIG_AsVal_long(unsigned long, long*)in CPPExampleWrapper.o
  "_rb_str_append", referenced from:
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_str_cat", referenced from:
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_str_cat2", referenced from:
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_str_new", referenced from:
      SWIG_FromCharPtrAndSize(char const*, unsigned long)in CPPExampleWrapper.o
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_str_new_cstr", referenced from:
      _SWIG_Ruby_NewClassInstance in CPPExampleWrapper.o
      _SWIG_Ruby_NewPointerObj in CPPExampleWrapper.o
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_string_value_ptr", referenced from:
      _wrap_XferParams_exclude_patterns_set(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _wrap_CPPTransfer_SetExcludePattern(int, unsigned long*, unsigned long)in CPPExampleWrapper.o
      _SWIG_Ruby_MangleStr in CPPExampleWrapper.o
      SWIG_AsCharPtrAndSize(unsigned long, char**, unsigned long*, int*)in CPPExampleWrapper.o
      Ruby_Format_TypeError(char const*, char const*, char const*, int, unsigned long)in CPPExampleWrapper.o
  "_rb_uint2big", referenced from:
      SWIG_From_unsigned_SS_long(unsigned long)in CPPExampleWrapper.o
  "_rb_undef_alloc_func", referenced from:
      _Init_CPPExample in CPPExampleWrapper.o
  "_rb_undef_method", referenced from:
      _SWIG_Ruby_define_class in CPPExampleWrapper.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

偶然ではないかもしれませんが、未定義のシンボルはすべてRubyCAPIのメンバーです。コンパイル時またはリンク時に何かが足りませんか?あるいは、この拡張機能の生成を容易にするために作成されたRubyの32ビットOS Xビルドに何か問題があるのでしょうか?

フィードバックをいただければ幸いです。

乾杯、

ジェームズ

4

1 に答える 1

0

この場合、問題はXcodeが64ビットバージョンのRubyをインストールし、それをシステムパスに配置したことであることが判明しました。この問題を解決するには、リンク行で32ビットバージョンのRubyバイナリへのパスを明示的に指定する必要がありました。

g++ -arch i386 -shared -fPIC -o ../lib/cppexample.so ./bin/CPPExampleWrapper.o ../qa_cpp_utils/bin/CPPExampleObject.o ../qa_cpp_utils/bin/CPPExampleCallbackFunctor.o ../qa_cpp_utils/lib/libcppexamplearchive.a -L/PATH/TO/32BIT/RUBY -framework CoreFoundation -lpthread

システムパス上のRubyのバージョンは、リンクされているアーキテクチャ用に構築されているため、これはLinuxでは問題ではありませんでした。

ジェームズ

于 2013-03-15T19:41:49.420 に答える