From: David B. <da...@da...> - 2009-01-07 16:39:02
|
Swig is not going to do anything unless you give it the actual definition of mylib::myclass. The declaration you have below is just a forward class declaration (which Swig just ignores because it provides no useful information). Cheers, Dave On Wed 07/01/09 11:12 AM , "Justin Bayer" bay...@go... sent: > Hi group, > > I have a dynamic library on OS X which has some classes/functions that > I want to access from python. So far I have done the following: > > mylib.i > --------------------------- > %module mylib > %{ > #include "mylib.h" > %} > > class mylib::myclass; > #define BLUBB 1 > --------------------------- > > then I run the following commands: > > $ swig -Wall -python -c++ src/swig/arac.i > *snip* > $ gcc -lmylib -Lpath/to/mylib -c -Wno-long-double > src/swig/arac_wrap.cxx -I/path/to/mylib/headers > -I/usr/local/include/python2.6 -I/usr/local/lib/python2.6/config -o > mylib_wrap.o > *snip* > $ gcc -lmylib -Lpath/to/mylib -Wno-long-double -bundle -undefined > suppress -flat_namespace mylib_wrap.o -o _mylib.so > *snip* > $ python -c "import mylib; dir(mylib._mylib)" > ['BLUBB', '__doc__', '__file__', '__name__', '__package__'] > > So myclass does not appear. What am I doing wrong? > > > Regards, > -Justin > > --------------------------------------------------------------------------- > ---Check out the new SourceForge.net Marketplace. > It is the best place to buy or sell services for > just about anything Open Source. > http://p.sf.net/sfu/Xq1LFB_______________________________________________ > Swig-user mailing list > Swi...@li...https://lists.sourceforge.net/lists/listinfo/swig-user > > |
From: John W. <jwh...@ta...> - 2009-01-07 17:18:24
|
Note also that this doesn't have to be a complete class definition. You can provide a subset of the class declaration in your interface file (mylib.i) to control which functionality you want to expose into the target language (Python, in your example). If you want all code in mylib.h wrapped, then just use: %include "mylib.h" instead of your forward declaration. -- John |
From: Justin B. <bay...@go...> - 2009-01-07 20:12:16
|
> %include "mylib.h" > > instead of your forward declaration. I did that - one problem though. I have an abstract base class of which the header file I do not %include. This leads to the derived classes to miss the base classes methods. I cannot %include the ABC though, because SWIG complains in that case. How do I get the methods of the ABC? |
From: William S F. <ws...@fu...> - 2009-01-07 20:51:20
|
Justin Bayer wrote: > > %include "mylib.h" > > > > instead of your forward declaration. > > I did that - one problem though. I have an abstract base class of > which the header file I do not %include. This leads to the derived > classes to miss the base classes methods. I cannot %include the ABC > though, because SWIG complains in that case. > > How do I get the methods of the ABC? Define the minimal amount of the ABC for SWIG to be useful, eg constructors, destructors virtual methods. Why is SWIG complaining about... that could be fixable if you explain the issue. William |
From: Justin B. <bay...@go...> - 2009-01-07 21:06:09
|
> Define the minimal amount of the ABC for SWIG to be useful, eg constructors, > destructors virtual methods. I was hoping I would not have to do that, but okay. > Why is SWIG complaining about... that could be > fixable if you explain the issue. It's actually gcc that complains: error: cannot allocate an object of abstract type 'MyABC' myabc.h:21: note: since type 'MyABC' has pure virtual functions |
From: William S F. <ws...@fu...> - 2009-01-07 21:16:59
|
Justin Bayer wrote: >> Define the minimal amount of the ABC for SWIG to be useful, eg constructors, >> destructors virtual methods. > > I was hoping I would not have to do that, but okay. > >> Why is SWIG complaining about... that could be >> fixable if you explain the issue. > > It's actually gcc that complains: > error: cannot allocate an object of abstract type 'MyABC' myabc.h:21: > note: since type 'MyABC' has pure virtual functions > Since SWIG has not parsed MyABC, it cannot determine that it is an ABC. You need to give it some more type information. It can get away with not having much type information, unlike the C++ compiler, but there are limits as to what you can hide as it will have to make assumptions which can lead to uncompileable code. William |