Boost - Cannot wrap pass-in vriables
Question: I tried to wrap a list to a vector of string using `<boost/python>`, where
comes "undefined symbol" error:

    
    
    /* *.cpp */
    using namespace std;
    using namespace boost::python;
    
    // convert python list to vector
    vector<string> list_to_vec_string(list& l) {
        vector<string> vec;
        for (int i = 0; i < len(l); ++i)
            vec.push_back(extract<string>( l[i] ));
        return vec;
    };
    
    bool validateKeywords(list& l){
        vector<string> keywords = list_to_vec_string(l);
        // do somethoing
    };
    

And I have

    
    
    /* wrapper.cpp */
    BOOST_PYTHON_MODULE(testmodule){
        // expose just one function
        def("validateKeywords", validateKeywords);
    }
    

When import the module, returns the error.

    
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: /usr/local/lib/python2.7/dist-packages/testmodule.so: undefined symbol: _Z16validateKeywordsSt6vectorISsSaISsEE
    

In my testing, everything works fine if I just convert returned values, i.e.
from `vector<string>` to `list`. Just couldn't make it work with pass-in
variables. Unless you pass in types that do not need a wrapper (int, char,
bool, void), the problem doesn't fade away.

* * *

**Update**

What you can do:

    
    
    /*pass in a variable that do not need a wrapper*/
    // testmodule.cpp
    void sayHello(const std::string& msg) {
        std::cout << msg << endl;
    }
    // wrapper.cpp
    BOOST_PYTHON_MODULE(testmodule) {
        def("sayHello", sayHello);
    }
    // demo.py
    import testmodule as tm
    tm.sayHello('hello!')
    // output
    >> hello!
    
    /*wrap a returned value from a function*/
    // testmodule.cpp
    vector<int> vecint(int i) {
        vector<int> v(i);
        return v;
    }
    // wrapper.cpp
    boost::python::list vecint_wrapper(int i) {
        boost::python::list l;
        vector<int> v = vecint(i);
        for (int j=0; j<v.size(); ++j)
            l.append(v[j]);
        return l; // then you have a list
    }
    
    /*cannot change passed in values to more complicate types*/
    


Answer: You miss get reference in line:

    
    
    def("validateKeywords", validateKeywords);
    

Try to use

    
    
    def("validateKeywords", &validateKeywords );
    

