470,631 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

first time use of swig, python and c++ .. it's a mess ... pleaseadvice


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:
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",

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
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
In file included from opcsvcapi_wrap.c:2490:
/opt/OV/include/opcsvcapi.h:12:18: error: vector: No such file or
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
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

Feb 26 '08 #1
0 1495

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
699 posts views Thread by mike420 | last post: by
13 posts views Thread by Grant Edwards | last post: by
5 posts views Thread by Alan Searle | last post: by
27 posts views Thread by Josh | last post: by
22 posts views Thread by lennart | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.