On Feb 27, 9:44 pm, "Bronner, Gregory" <[EMAIL PROTECTED]> wrote: > The operator= stuff is usually innocuous. > The compiler died because it couldn't find 'vector', which is reasonable, > since it thought it was compiling a C file. > > Probably because you swigged the file without the magic "-c++" option -- I'm > not sure how distutils passes arguments to swig, but if you do it from the > command line, you'll do something like swig -c++ -python -I<path to python> > <file> and it will generate a .cpp file and a .py file, which will > (hopefully) compile. > > I'd focus on doing it manually, then getting distutils to work properly. > > -----Original Message----- > From: Hyuga [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 27, 2008 10:01 AM > To: [EMAIL PROTECTED] > Subject: Re: first time use of swig, python and c++ .. it's a mess ... please > advice > > On Feb 26, 3:38 pm, Eric von Horst <[EMAIL PROTECTED]> wrote: > > Hi, > > > we have a third-party product that has a C++ api on HP-UX. > > > I would like be able to use the API in Python (as I remember Python is > > good at doing this). > > > I have no experience with this so I Googled and tried to find some > > info on what I had to do. > > > So, I installed Python 2.4.4 and Swig 1.3.33 > > > The header file to the library is '/opt/OV/include/opcsvcapi.h'. > > > I created a SWIG file with the following content: > > " > > %module opcsvcapi > > %{ > > /* Includes the header in the wrapper code */ > > #include "/opt/OV/include/opcsvcapi.h" > > %} > > > /* Parse the header file to generate wrappers */ > > %include "/opt/OV/include/opcsvcapi.h" > > " > > Then I ran the cmd: > > # swig -c++ -python opcsvcapi.i > > with output: > > " > > /opt/OV/include/opcsvcapi.h:41: Warning(362): operator= ignored > > /opt/OV/include/opcsvcapi.h:46: Warning(503): Can't wrap 'operator > > Type' unless renamed to a valid identifier. > > " > > > The result are two files: > > opcsvcapi.py > > opcsvcapi_wrap.cxx > > > I created a 'setup.py' file with the following content: > > " > > import distutils > > from distutils.core import setup, Extension > > > setup(name = "opcsvcapi", > > version = "1.0", > > ext_modules = [Extension("_opcsvcapi", > > ["opcsvcapi.i","opcsvcapi.cxx"])]) > > " > > > Then I run: python setup.py build > > > This results in an extra file: > > opcsvcapi_wrap.c and a 'build' directory > > > and the following errors: > > " > > running build > > running build_ext > > building '_opcsvcapi' extension > > swigging opcsvcapi.i to opcsvcapi_wrap.c swig -python -o > > opcsvcapi_wrap.c opcsvcapi.i creating build creating > > build/temp.hp-ux-B.11.11-9000-800-2.4 > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict- > > prototypes -fPIC -I/usr/local/include/python2.4 -c opcsvcapi_wrap.c -o > > build/temp.hp-ux-B.11.11-9000-800-2.4/opcsvcapi_wrap.o > > In file included from /usr/local/include/python2.4/Python.h:8, > > from opcsvcapi_wrap.c:118: > > /usr/local/include/python2.4/pyconfig.h:851:1: warning: > > "_POSIX_C_SOURCE" redefined > > <command line>:1:1: warning: this is the location of the previous > > definition In file included from opcsvcapi_wrap.c:2490: > > /opt/OV/include/opcsvcapi.h:12:18: error: vector: No such file or > > directory In file included from opcsvcapi_wrap.c:2490: > > /opt/OV/include/opcsvcapi.h:15: error: expected '=', ',', ';', 'asm' > > or '__attribute__' before 'SvcAPI' > > opcsvcapi_wrap.c: In function 'Swig_var_SvcAPI_set': > > opcsvcapi_wrap.c:2505: error: 'SvcAPI' undeclared (first use in this > > function) > > opcsvcapi_wrap.c:2505: error: (Each undeclared identifier is reported > > only once > > opcsvcapi_wrap.c:2505: error: for each function it appears in.) > > opcsvcapi_wrap.c:2505: error: 'namespace' undeclared (first use in > > this function) > > opcsvcapi_wrap.c:2505: error: expected expression before ')' token > > opcsvcapi_wrap.c: In function 'init_opcsvcapi': > > opcsvcapi_wrap.c:3064: error: 'Swig_var_SvcAPI_get' undeclared (first > > use in this function) > > error: command 'gcc' failed with exit status 1 " > > > and that's it. > > > Any idea what I am doing wrong? > > > Any help much appreciated > > > Kris > > Well, the errors you got from the compiler are just confusing to me, but I > suspect it goes back to the warning you got from SWIG. Some class in there > is overriding the = operator, but since that can't be done in Python, you > need to give it some special instructions on how to handle that. > > For example, if you have Foo::operator=, in your SWIG header include a line > like: > %rename(assign) Foo::operator= > > Then in the Python module, the Foo class will have an assign method. > > Hyuga > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - > > This message is intended only for the personal and confidential use of the > designated recipient(s) named above. If you are not the intended recipient > of this message you are hereby notified that any review, dissemination, > distribution or copying of this message is strictly prohibited. This > communication is for information purposes only and should not be regarded as > an offer to sell or as a solicitation of an offer to buy any financial > product, an official confirmation of any transaction, or as an official > statement of Lehman Brothers. Email transmission cannot be guaranteed to be > secure or error-free. Therefore, we do not represent that this information > is complete or accurate and it should not be relied upon as such. All > information is subject to change without notice. > > -------- > IRS Circular 230 Disclosure: > Please be advised that any discussion of U.S. tax matters contained within > this communication (including any attachments) is not intended or written to > be used and cannot be used for the purpose of (i) avoiding U.S. tax related > penalties or (ii) promoting, marketing or recommending to another party any > transaction or matter addressed herein.
That is indeed what I did. A do get .cpp file. The thin is that if I run setup, the library is again swigged but without the -c++ option (see original post) but honestly, I don't know what to do after I have the .cpp file. I could not find any docs that explained clearly how to compile if you are using C++ The only thing I found was that it was not so straightforward So, again, any help is very much appreciated -- http://mail.python.org/mailman/listinfo/python-list