Create two bodies: The first one should be a static body and can have any kind of shape. The second one should be dynamic and should consist of two shapes (see attachment). The joint you are searching for is called revolute joint.
Assume that the bodies are called body1 and body2, then do this:
Code:
b2RevoluteJointDef jointDef;
jointDef.Initialize(body1, body2, body1->GetWorldCenter());
jointDef.maxMotorTorque = 10.0f;
jointDef.motorSpeed = 10.0f;
jointDef.enableMotor = true;
jointDef.localAnchorB.Set(x, y);
whereby x and y are the coordinates of the (local, i.e. relative to the body) anchor point.