[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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



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


Reply to: