From: Marcelo M. <mm...@ac...> - 2005-12-20 20:25:59
|
Could you send me the lines around the error you have with __attribute__, ie foo_tcl.cpp:1542: error: parse error before `__attribute__' in the file there is only one place where we use attribute, in SWIGUNUSED, is that the problem? Marcelo Mike Kaplan wrote: > I am trying to use std:vector in tcl and am having the problem where > some methods do not work. I saw in the archives that other users were > having this problem and that the suggested solution was to try the > latest version of swig from CVS. I built swig today (2005-12-19) and > encoutered the same issue where the std::vector size function (among > others) does not work as it expects types > _p_p_std__vector_T<type> > where the working functions expect type > _p_std__vector_T<type>. > > > Additionally, using vector with type <foo *>, the "get" method returns > type _p_p_foo which I then cannot pass into any of the function > generated for class foo and is itself an unusable function. I don't > know if this is more of the same problem or a separate issue. > > Lastly, the CVS version of swig generates files that my cpp compiler > won't compile > gcc version 3.3.5 (Debian 1:3.3.5-13) > due to the use of __attribute__ > > foo_tcl.cpp:1542: error: parse error before `__attribute__' > > However, removing the __attribute__ macro definition allows it to compile. > > The sample code I used is as follows: > > > ############ foo.h ################### > > #include <vector> > using namespace std; > > class bar > { > private: > int id; > public: > bar(); > bar(int i); > ~bar(); > int get_id(); > void set_id(int id); > }; > > class foo > { > public: > vector<bar *> bars; > foo(); > }; > > > ######################################### > > ################ foo.cpp ################## > #include "foo.h" > > bar::bar() > { > id = 0; > } > > bar::bar(int i) > { > id = i; > } > > void bar::set_id(int id) > { > this->id = id; > } > > int bar::get_id() > { > return id; > } > > bar::~bar() {} > > foo::foo() > { > bars.push_back(new bar(1)); > bars.push_back(new bar(5)); > bars.push_back(new bar(7)); > } > > ################################################### > > ################## Makefile ######################### > > all: libfoo.so > > INCLUDES = -I/opt/tcl/include > > .cpp.o: > c++ -c $(INCLUDES) $< -o $@ > > ### tcl library > foo_tcl.cpp: foo.swg foo.h > swig -c++ -tcl -o foo_tcl.cpp foo.swg > > libfoo.so: foo_tcl.o foo.o > c++ -shared -Wl,-soname,$@ foo_tcl.o foo.o -o $@ > > #################################################### > > ################### foo.swg ########################## > %module foo > %{ > #include "foo.h" > %} > > %include "std_vector.i" > using namespace std; > > namespace std { > %template(vectorBar) vector<bar *>; > } > > %include "foo.h" > > ###################################################### > > ################## sample interactions ################### > > % load ./libfoo.so > % set x [new_bar] > _60730708_p_bar > % $x get_id > 0 > % $x set_id 15 > % $x get_id > 15 > % set y [new_foo] > _30b90a08_p_foo > % set bars [$y cget -bars] > _30b90a08_p_std__vector_Tbar_p_t > % $bars size > list of bar * expected > % vectorBar_size $bars > list of bar * expected > % set tbar [$bars get 0] > _f0b90a08_p_p_bar > % $tbar get_id > invalid command name "_f0b90a08_p_p_bar" > > ###################################################### > > Thanks for any advice / help you can offer, > > Michael N. Kaplan > Naval Undersea Warfare Center > > |