問候的StackOverflow社區編譯爲Ruby SWIG C++包裝對象,爲i386硬件架構未定義符號在連接使用-m32選項
我有一個生成一個C++靜態檔案庫中的Ruby的C API封裝了一大口項目。我在64位Linux下生成和編譯代碼時沒有任何問題(在Fedora和Debian下測試過)。不幸的是,存檔的OS X版本只有32位。我內置的Ruby on OS X 32位版本,以生成,編譯和鏈接,將被作爲Ruby的C本機擴展的共享對象:
$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
也許不是那麼巧合的是,所有未定義的符號的是紅寶石C API的成員。我在編譯或鏈接時錯過了什麼嗎?或者,可能是爲了便於生成此擴展而創建的Ruby的32位OS X版本出現問題?
任何反饋,非常感謝。
乾杯,
詹姆斯