0

I have written a function in C++ and built successfully.

However, if I just calling it from another function in C++, then the built failed.

double getlistvalue(boost::python::list l, int index)
{
    if (index = -1)
        return 0;
    else
        return boost::python::extract<double>(l[index]);

}

double xx(boost::python::list l, int index)
{
    return getlistvalue(l, index);
}

the above code, without the second function, it builds.

here is the error info: error info

Please share ideas of how to solve it. thanks a lot.

1 Answer 1

1

You are passing the lists by value, which requires a copy constructor. The error message is telling you that no copy constructor has been provided for list. The solution therefore is to pass the list by reference:

double getlistvalue(const boost::python::list &l, int index)

(and the same for the other function).

In general, passing complex objects like a list by value is a bad idea, since even if a copy constructor has been provided, actually making the copy can be quite expensive.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot for the reply, your answer is correct, will solve the problem. Found that another way is to add #define BOOST_PYTHON_STATIC_LIB before including the boost/python header. Just for people who have similar problems.
@datalearning The Python list has a copy constructor. As you have discovered, the error messages (unresolved symbols) is indicating that one needs to link against the Boost.Python library with the appropriate symbol visibility. Python objects are reference counted, and Boost.Python objects are essentially smart pointers. As a result, passing these objects by value is cheap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.