  We introduce a new wall-crossing formula which combines and generalizes the
Cecotti-Vafa and Kontsevich-Soibelman formulas for supersymmetric 2d and 4d
systems respectively. This 2d-4d wall-crossing formula governs the
wall-crossing of BPS states in an N=2 supersymmetric 4d gauge theory coupled to
a supersymmetric surface defect. When the theory and defect are compactified on
a circle, we get a 3d theory with a supersymmetric line operator, corresponding
to a hyperholomorphic connection on a vector bundle over a hyperkahler space.
The 2d-4d wall-crossing formula can be interpreted as a smoothness condition
for this hyperholomorphic connection. We explain how the 2d-4d BPS spectrum can
be determined for 4d theories of class S, that is, for those theories obtained
by compactifying the six-dimensional (0,2) theory with a partial topological
twist on a punctured Riemann surface C. For such theories there are canonical
surface defects. We illustrate with several examples in the case of A_1
theories of class S. Finally, we indicate how our results can be used to
produce solutions to the A_1 Hitchin equations on the Riemann surface C.
