Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SWIG, STL, Python: std_common.i:9: Error: Syntax error in input(1).

177 views
Skip to first unread message

Joost Witteveen

unread,
Mar 19, 2008, 7:20:10 AM3/19/08
to
I try the SWIG STL vector example from:

http://www.swig.org/Doc1.3/Library.html#Library_nn15

calling swig seems to work for all languages, except for python (the
one I want):

joostje@muso:~/ar$ swig -python example.i
/usr/share/swig1.3/python/std_common.i:9: Error: Syntax error in input(1).

Does anyone know what I can do to make it work?
A google search only showed
http://blog.isnotworking.com/2006/08/word-of-caution-distutils-swig-stl.html
about setting an undocumented swig_opts=['-c++'] option in setup.py, I
don't know what setup.py file that is (and strace shows swig doesn't
look for setup.py files).


Other languages work OK with the same example.[ih] files:

joostje@muso:~/ar$ swig -tcl example.i
joostje@muso:~/ar$ swig -perl5 example.i
joostje@muso:~/ar$ swig -java example.i
joostje@muso:~/ar$ swig -csharp example.i

Here are the example.i and example.h files, copied from
http://www.swig.org/Doc1.3/Library.html#Library_nn15

joostje@muso:~/ar$ cat example.i
%module example
%{
#include "example.h"
%}

%include "std_vector.i"
// Instantiate templates used by example
namespace std {
%template(IntVector) vector<int>;
%template(DoubleVector) vector<double>;
}

// Include the header file with above prototypes
%include "example.h"
joostje@muso:~/ar$ cat example.h
/* File : example.h */

#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>

double average(std::vector<int> v) {
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
}

std::vector<double> half(const std::vector<double>& v) {
std::vector<double> w(v);
for (unsigned int i=0; i<w.size(); i++)
w[i] /= 2.0;
return w;
}

void halve_in_place(std::vector<double>& v) {
std::transform(v.begin(),v.end(),v.begin(),
std::bind2nd(std::divides<double>(),2.0));
}

--
Thanks,
Joost Witteveen


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Joost Witteveen

unread,
Mar 20, 2008, 8:50:12 AM3/20/08
to
> joostje@muso:~/ar$ swig -python example.i
> /usr/share/swig1.3/python/std_common.i:9: Error: Syntax error in input(1).

At least when giving the -c++ argument to swig it works better:

joostje@muso:~/ar$ swig -python -c++ example.i

doesn't look ideal (should accept same arguments for all languages, I
guess), but at least it works.

0 new messages