I am using the Python C API and trying to create a function that will allocate new instances of PyTypeObjects to use in several C++ classes. The idea is that each class would have a pointer to a PyTypeObject that would get instantiated with this factory. The pointers must be static. 
However, I'm having issues with this approach.

In the class that contains the pointer to the PyTypeObject, I get the "undefined reference" linker error when I try to set that static variable equal to the result of the factory function (which is in another class but is static). I suppose this makes sense because the function wouldn't happen until runtime but I don't know another way to do this.
I don't know how to set the PyTypeObject fields dynamically because the first field is always a macro: PyObject_VAR_HEAD. 

Hope this makes sense. Basically, I'm trying to make it so several classes don't have to redefine PyTypeObject statically, but can instead instantiate their PyTypeObject variables from a factory function.
Try this: create a 'template' PyTypeObject, and use struct copying (or memcpy) to clone the basic template. Then you can fill it in with the requisite field definitions after that. This solves (2), since you only have to declare the full PyTypeObject once.
For your first point, you just set the static variable from your module init instead of doing it in the static variable declaration. So, it won't be set until your module actually initializes.
If you plan on doing this often, it may be worth looking at Boost::Python, which simplifies the process of generating CPython wrappers from C++ classes.
Static factory for PyTypeObject