There should be no problems with Boost.Python using static data members or static member functions on C++ classes being exposed. Is it possible that this is a false-positive? Alternatively, for more complex and specific cases where the same template is instantiated in multiple translation units, then with dynamic libraries, multiple instances of static data members with the same symbolic name may reside within the same process space.
Regardless, here is a complete example demonstrating the expected behavior of static member functions and static data members on a class exposed with Boost.Python:
#include <boost/python.hpp>
// Basic mockup type.
class spam
{
public:
static void set_x(unsigned int x) { x_ = x; }
static unsigned int get_x() { return x_; };
private:
spam() {};
spam(const spam&);
spam& operator=(const spam&);
static unsigned int x_;
};
unsigned int spam::x_ = 0;
// Auxiliary function.
bool spam_check_x(unsigned int x)
{
return x == spam::get_x();
}
BOOST_PYTHON_MODULE(example)
{
namespace python = boost::python;
python::class_<spam, boost::noncopyable>("Spam", python::no_init)
.def("setX", &spam::set_x)
.staticmethod("setX")
.def("getX", &spam::get_x)
.staticmethod("getX")
.def("checkX", &spam_check_x)
.staticmethod("checkX")
;
}
Interactive usage:
>>> from example import Spam
>>> x = 42
>>> assert(Spam.getX() != x)
>>> assert(not Spam.checkX(x))
>>> Spam.setX(x)
>>> assert(Spam.getX() == x)
>>> assert(Spam.checkX(x))
>>> x = 43
>>> assert(Spam.getX() != x)
>>> assert(not Spam.checkX(x))