[PyKDE] Re: How can I use SIP to wrap STL class?
Jim Bublitz
jbublitz at nwinternet.com
Mon Apr 15 00:25:43 BST 2002
On 14-Apr-02 ejoy <ejoy at peoplemail.com.cn> wrote:
> On Wednesday 10 April 2002 17:29, you wrote:
>> If you can't modify the C++ code to return a Python list, you
>> will need to write %MemberCode (following foo's declaration in
>> the .sip file) to accomplish that (I'm sure Phil will correct
>> me if I'm wrong). "ListType" can be any name you choose.
>> "sipCpp" and "sipCppPtr" in the PyQt/PyKDE2 examples are the
>> pointers that represent the data to and from C++ respectively
>> - use those names.
> Thanks Jim for his kindly reply.I've created a vecstring.sip from
> qstrlist.sip
> and a a.sip to wrap:
>#include <vector>
>#include <string>
> using namespace std;
> class A {
> public:
> A();
> ~A();
> void foo(const vector<string>&,vector<string>&);
> };
> The a.sip looks like:
> %Module A
> %Include vecstring.sip
> %HeaderCode
>#include "a.h"
> %End
> class A{
> public:
> void foo(const VecString&,VecString&);
> };
I don't see anything wrong so far ...
> and the vecstring.sip is in attachment.
I looked at the attachment quickly and it looks correct.
> The compile progress is ok with the following output:
> /usr/local/bin/sip -s ".cpp" -c sip a.sip
This step should produce a .h and .cpp file - the .cpp file should
contain the code you wrote in vecstring.sip. I'm not sure how this
will be named - something like "sipvecstring.cpp" or
"sipAvecstring.cpp" I'd guess.
> cd sip && make
> make[1]: Entering directory `/home/zl/prj/py/py/sip'
> g++ -c -I.. -I. -I/usr/include/python2.1
> -I/usr/local/include/sip
> Acmodule.cpp
> g++ -c -I.. -I. -I/usr/include/python2.1
> -I/usr/local/include/sip sipAA.cpp
> g++ -shared -L/usr/local/lib/ -lsip -o libAcmodule.so *.o
> make[1]: Leaving directory `/home/zl/prj/py/py/sip'
I don't see any place where the code for the %Mapped Type stuff is
being compiled - you'll need to make sure the file sip created from
vecstring.sip is included in the build (in the makefile). a.sip
produced Acmodule.cpp, and your 'A 'class produced sipAA.cpp, but
neither includes/contains the vecstring code. sip produces a .cpp/.h
file for each class or %MappedType in the input set.
> When I try to import A from python interpreter a error occurs:
>
>>>> import A
> Traceback (most recent call last):
> File "<pyshell#0>", line 1, in ?
> import A
> File "/home/zl/prj/py/py/sip2/A.py", line 5, in ?
> import libAc
> ImportError: /home/zl/prj/py/py/sip2/libAcmodule.so: undefined
> symbol:
> sipConvertTo_VecString__FP7_objectPPt6vector2Zt12basic_string3ZcZt
> 18string_char_traits1ZcZt24__default_alloc_template2b1i0Zt9allocat
> or1Zt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc
> _template2b1i0Pi
>>>> import A
That's an amazingly mangled name! My guess is you're getting the
error because the %Mapped Type code (which will produce
sipConvertTo... and sipConvertFrom... functions) hasn't been
compiled in and linked.
> Seems like a linking problem but I'm not sure.
> Can you tell me where is the problem?
Hope that helps - I can't see any other problem at the moment. You
seem to have done a good job figuring out how sip operates.
Jim
More information about the PyQt
mailing list