2 votes

Symbole non défini pour l'architecture i386 lors de la liaison de SWIG C++ Wrapper Object for Ruby compilé avec l'option -m32

Salutations à la communauté StackOverflow,

J'ai un projet SWIG qui génère un wrapper API Ruby C pour une bibliothèque d'archives statiques C++. Je n'ai aucun problème pour générer et compiler le code sous Linux 64 bits (testé sous Fedora et Debian). Malheureusement, la version OS X de l'archive n'est que 32 bits. J'ai construit une version 32 bits de Ruby sous OS X afin de générer, compiler et lier l'objet partagé qui sera utilisé comme l'extension native Ruby C :

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

Tous les objets sont compilés avec l'option -m32 drapeau :

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

et liés en conséquence :

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

Lors de la liaison, je reçois une erreur indiquant que les symboles référencés dans CPPExampleWrapper.o sont indéfinis pour l'architecture 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

Ce n'est peut-être pas une coïncidence si tous les symboles non définis sont des membres de l'API C de Ruby. Est-ce que je rate quelque chose à la compilation ou à la liaison ? Ou peut-être y a-t-il un problème avec la version 32 bits de Ruby pour OS X créée pour faciliter la génération de cette extension ?

Tout commentaire est le bienvenu.

A la vôtre,

James

0voto

James Wilson Points 21

Dans ce cas, il s'avère que le problème était que Xcode avait installé une version 64 bits de Ruby et l'avait placée dans le chemin du système. Afin de résoudre le problème, j'ai dû spécifier explicitement le chemin vers la version 32 bits du binaire Ruby sur la ligne de liaison :

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

Ce n'était pas un problème sous Linux, car la version de Ruby sur le chemin du système était construite pour l'architecture à lier.

James

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X