From: Alex <x37...@gm...> - 2008-07-28 08:14:34
|
The problem with building a shared object (library) is that I have a singleton class that is accessed both from the wrapper code and from my main code.. when i build a shared object, the swig wrapper code's ::instance() actually gives a different object than when the main code calls ::instance().. this is not the case when i build wrapper code directly into my app and call Init_foo directly before loading the ruby code (but then i cannot include stl_vector.i without segfaulting). Maybe someone can suggest a way around this? How do i create a shared object and allow it to access the same pointer when calling ::instance() on a swig wrapped singleton object and in some c++ code that loads an interpreter that in turn loads that shared object. -Alex On Fri, Jul 25, 2008 at 1:58 PM, William S Fulton <ws...@fu...> wrote: > Warning 322 only appears when using -Wall. You can ignore those, but really > the SWIG library should be fixed. I looked at your tarball. I don't know > ruby well, so certainly can't tell you how to run the ruby interpreter from > C++ code. I suggest you take the conventional route and build a shared > object and run the ruby interpreter from the command line. This works fine > and there is an example: Examples/ruby/std_vector. You need to make one > small change and change all instance of 'length' to 'size' in runme.rb. Then > it all works... > > > ~/swig/trunk/Examples/ruby/std_vector$ make > make -f ../../Makefile CXXSRCS='' SWIG='../../../preinst-swig' \ > SWIGOPT='' TARGET='example' INTERFACE='example.i' ruby_cpp > make[1]: Entering directory > `/home/william/swig/trunk/Examples/ruby/std_vector' > ../../../preinst-swig -c++ -ruby example.i > g++ -c -fpic -fPIC example_wrap.cxx -I/usr/lib/ruby/1.8/i486-linux > g++ -shared example_wrap.o -o example.so > make[1]: Leaving directory > `/home/william/swig/trunk/Examples/ruby/std_vector' > ~/swig/trunk/Examples/ruby/std_vector$ ruby runme.rb > 2.5 > 2.5 > 0.5; 0.75; 1.0; 1.25; 1.5; > 0.5; 1.0; 1.5; 2.0; > 0.5; 1.0; 1.5; 2.0; > ~/swig/trunk/Examples/ruby/std_vector$ > > William > > Alex wrote: >> >> okay, good call. here is an example.. >> >> the code runs as planned if i comment out : >> %include std_vector.i >> >> in the foo.i interface file. >> >> but with that %include statement, the code builds (with the warnings >> below) and segfaults when I run the executable. >> >> 07:35:57 $ make >> swig -Wall -c++ -ruby foo.i >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >> Redundant redeclaration of 'map_bang', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >> previous declaration of 'map_bang'. >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >> Redundant redeclaration of '__delete__', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >> previous declaration of '__delete__'. >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >> Redundant redeclaration of 'map_bang', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >> previous declaration of 'map_bang'. >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >> Redundant redeclaration of '__delete__', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >> previous declaration of '__delete__'. >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >> Redundant redeclaration of 'map_bang', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >> previous declaration of 'map_bang'. >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >> Redundant redeclaration of '__delete__', >> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >> previous declaration of '__delete__'. >> g++ foo.cpp main.cpp foo_wrap.cxx -o foo_test >> -I/usr/lib/ruby/1.8/i486-linux/ -lruby1.8 >> >> here is the gdb backtrace: >> Program received signal SIGSEGV, Segmentation fault. >> [Switching to Thread 0xb7bb46c0 (LWP 19099)] >> 0xb7f090de in st_lookup () from /usr/lib/libruby1.8.so.1.8 >> (gdb) bt >> #0 0xb7f090de in st_lookup () from /usr/lib/libruby1.8.so.1.8 >> #1 0xb7edd312 in rb_intern () from /usr/lib/libruby1.8.so.1.8 >> #2 0x0804a5d9 in __static_initialization_and_destruction_0 >> (__initialize_p=1, __priority=65535) at foo_wrap.cxx:2018 >> #3 0x0804a72c in global constructors keyed to >> _ZN4swig8GC_VALUE7hash_idE () at foo_wrap.cxx:4114 >> #4 0x08050415 in __do_global_ctors_aux () >> #5 0x08049628 in _init () >> #6 0x080503b9 in __libc_csu_init () >> #7 0xb7c1a3f1 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6 >> #8 0x08049b11 in _start () >> (gdb) >> >> hopefully I'm just doing something obviously wrong.. >> >> --Alex >> >> >> On Thu, Jul 3, 2008 at 2:48 PM, William S Fulton >> <ws...@fu...> wrote: >>> >>> Alex wrote: >>>> >>>> I am using swig to generate a ruby interface for some c++ code I've >>>> written. I want to include std_vector so that (hopefully) I input >>>> ruby arrays into this method I have that accepts std::vector<int>. >>>> >>>> anyways, if I build without.. >>>> %include std_vector.i >>>> ..my application builds fine, I can run my it but I cannot use this >>>> method in ruby. >>>> >>>> If I do include that I get this output: >>>> >>>> $ swig -Wall -c++ -ruby datajockey.i >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >>>> Redundant redeclaration of 'map_bang', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >>>> previous declaration of 'map_bang'. >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >>>> Redundant redeclaration of '__delete__', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:136: Warning(322): >>>> previous declaration of '__delete__'. >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >>>> Redundant redeclaration of 'map_bang', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >>>> previous declaration of 'map_bang'. >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >>>> Redundant redeclaration of '__delete__', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:137: Warning(322): >>>> previous declaration of '__delete__'. >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >>>> Redundant redeclaration of 'map_bang', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >>>> previous declaration of 'map_bang'. >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >>>> Redundant redeclaration of '__delete__', >>>> /usr/share/swig1.3/ruby/rubycontainer_extended.swg:138: Warning(322): >>>> previous declaration of '__delete__'. >>>> >>>> then, after building and running my app I get a segfault right away. >>>> >>>> below is the gdb backtrace. >>>> >>>> Program received signal SIGSEGV, Segmentation fault. >>>> [Switching to Thread 0xb60f0ac0 (LWP 21283)] >>>> 0xb7e1324e in st_lookup () from /usr/lib/libruby1.8.so.1.8 >>>> (gdb) bt >>>> #0 0xb7e1324e in st_lookup () from /usr/lib/libruby1.8.so.1.8 >>>> #1 0xb7de74e2 in rb_intern () from /usr/lib/libruby1.8.so.1.8 >>>> #2 0x080863dc in __static_initialization_and_destruction_0 () >>>> #3 0x0809e2b5 in __do_global_ctors_aux () >>>> #4 0x08054820 in _init () >>>> #5 0x0809e259 in __libc_csu_init () >>>> #6 0xb6f853f1 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6 >>>> #7 0x08057091 in _start () >>>> >>>> >>>> Any ideas what's up? Am I doing something wrong or, is there a bug in >>>> the swig-ruby library? >>>> >>> No idea without a small standalone test case. We don't see those problems >>> in >>> the numerous testcases that ship with SWIG. >>> >>>> btw, while building [with and without that include statement], i get a >>>> bunch of these: >>>> swig/datajockey_wrap.cxx:5463: warning: unused parameter 'self' >>>> swig/datajockey_wrap.cxx:5479: warning: unused parameter 'argv' >>>> .... >>>> and a couple of these: >>>> swig/datajockey_wrap.cxx: In function 'VALUE >>>> _wrap_new_MixerPanelModel(int, VALUE*, VALUE)': >>>> swig/datajockey_wrap.cxx:5193: warning: 'argv[0]' may be used >>>> uninitialized in this function >>>> >>> These are due to extra high warning levels in your compiler. They ought >>> to >>> be suppressed, but can possibly be ignored. >>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> ------------------------------------------------------------------------- >>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! >>> Studies have shown that voting for your favorite open source project, >>> along with a healthy diet, reduces your potential for chronic lameness >>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08 >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Swig-user mailing list >>> Swi...@li... >>> https://lists.sourceforge.net/lists/listinfo/swig-user > > |