I am using Boost 1.44.0 to cross-compile C++ code for Python. I’m trying to expose a static constant defined in ExposureSinusoid.h like this:
static const UINT _min_exp = 20;
And in the file extending.cpp, I am trying to expose them like this, according to documentation from the Boost team:
.def_readonly("_min_exp", &ExposureSinusoid::_min_exp)
The library compiles fine but when the program runs I get the following error:
ImportError: ../linux/appfs/master/usr/lib/python2.6/pa/vision/_vision.so: undefined symbol: _ZN16ExposureSinusoid8_min_expE
To rule out the possibility the Boost wasn’t finding the constant, I tried changing its name in extending.cpp and the library failed to compile. So it seems like the constant is being found during compilation but it isn’t being properly exposed.
In addition to being declared,
staticdata members must also be defined.The only scenario where the definition of a
staticdata member may be omitted is when the data member in question is aconstfundamental integral type, and it is initialized with a constant expression, and it is never ODR-used (see the C++03 standard, §9.4.2/4); however, taking the address of a variable qualifies as ODR-usage, so in your case a definition must be supplied.